]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_rados.h
53fdb9b55627de517c3753ec2d4e2ff613983f53
[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(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();
416 int open_gc_pool_ctx();
417 int open_lc_pool_ctx();
418 int open_objexp_pool_ctx();
419 int open_reshard_pool_ctx();
420 int open_notif_pool_ctx();
421
422 int open_pool_ctx(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;
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 RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_rados_ref *ref);
464 int get_system_obj_ref(const rgw_raw_obj& obj, rgw_rados_ref *ref);
465 uint64_t max_bucket_id;
466
467 int get_olh_target_state(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(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(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 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
510 int get_obj_head_ioctx(const RGWBucketInfo& bucket_info, const rgw_obj& obj, librados::IoCtx *ioctx);
511 public:
512 RGWRados(): timer(NULL),
513 gc(NULL), lc(NULL), obj_expirer(NULL), use_gc_thread(false), use_lc_thread(false), quota_threads(false),
514 run_sync_thread(false), run_reshard_thread(false), meta_notifier(NULL),
515 data_notifier(NULL), meta_sync_processor_thread(NULL),
516 bucket_index_max_shards(0),
517 max_bucket_id(0), cct(NULL),
518 binfo_cache(NULL), obj_tombstone_cache(nullptr),
519 pools_initialized(false),
520 quota_handler(NULL),
521 cr_registry(NULL),
522 pctl(&ctl),
523 reshard(NULL) {}
524
525 RGWRados& set_use_cache(bool status) {
526 use_cache = status;
527 return *this;
528 }
529
530 RGWLC *get_lc() {
531 return lc;
532 }
533
534 RGWRados& set_run_gc_thread(bool _use_gc_thread) {
535 use_gc_thread = _use_gc_thread;
536 return *this;
537 }
538
539 RGWRados& set_run_lc_thread(bool _use_lc_thread) {
540 use_lc_thread = _use_lc_thread;
541 return *this;
542 }
543
544 RGWRados& set_run_quota_threads(bool _run_quota_threads) {
545 quota_threads = _run_quota_threads;
546 return *this;
547 }
548
549 RGWRados& set_run_sync_thread(bool _run_sync_thread) {
550 run_sync_thread = _run_sync_thread;
551 return *this;
552 }
553
554 RGWRados& set_run_reshard_thread(bool _run_reshard_thread) {
555 run_reshard_thread = _run_reshard_thread;
556 return *this;
557 }
558
559 uint64_t get_new_req_id() {
560 return ++max_req_id;
561 }
562
563 librados::IoCtx* get_lc_pool_ctx() {
564 return &lc_pool_ctx;
565 }
566
567 librados::IoCtx& get_notif_pool_ctx() {
568 return notif_pool_ctx;
569 }
570
571 void set_context(CephContext *_cct) {
572 cct = _cct;
573 }
574 void set_store(rgw::sal::RGWRadosStore *_store) {
575 store = _store;
576 }
577
578 RGWServices svc;
579 RGWCtl ctl;
580
581 RGWCtl *pctl{nullptr};
582
583 /**
584 * AmazonS3 errors contain a HostId string, but is an opaque base64 blob; we
585 * try to be more transparent. This has a wrapper so we can update it when zonegroup/zone are changed.
586 */
587 string host_id;
588
589 RGWReshard *reshard;
590 std::shared_ptr<RGWReshardWait> reshard_wait;
591
592 virtual ~RGWRados() = default;
593
594 tombstone_cache_t *get_tombstone_cache() {
595 return obj_tombstone_cache;
596 }
597 const RGWSyncModuleInstanceRef& get_sync_module() {
598 return sync_module;
599 }
600 RGWSyncTraceManager *get_sync_tracer() {
601 return sync_tracer;
602 }
603
604 int get_required_alignment(const rgw_pool& pool, uint64_t *alignment);
605 void get_max_aligned_size(uint64_t size, uint64_t alignment, uint64_t *max_size);
606 int get_max_chunk_size(const rgw_pool& pool, uint64_t *max_chunk_size, uint64_t *palignment = nullptr);
607 int get_max_chunk_size(const rgw_placement_rule& placement_rule, const rgw_obj& obj, uint64_t *max_chunk_size, uint64_t *palignment = nullptr);
608
609 uint32_t get_max_bucket_shards() {
610 return RGWSI_BucketIndex_RADOS::shards_max();
611 }
612
613
614 int get_raw_obj_ref(const rgw_raw_obj& obj, rgw_rados_ref *ref);
615
616 int list_raw_objects_init(const rgw_pool& pool, const string& marker, RGWListRawObjsCtx *ctx);
617 int list_raw_objects_next(const string& prefix_filter, int max,
618 RGWListRawObjsCtx& ctx, list<string>& oids,
619 bool *is_truncated);
620 int list_raw_objects(const rgw_pool& pool, const string& prefix_filter, int max,
621 RGWListRawObjsCtx& ctx, list<string>& oids,
622 bool *is_truncated);
623 string list_raw_objs_get_cursor(RGWListRawObjsCtx& ctx);
624
625 CephContext *ctx() { return cct; }
626 /** do all necessary setup of the storage device */
627 int initialize(CephContext *_cct) {
628 set_context(_cct);
629 return initialize();
630 }
631 /** Initialize the RADOS instance and prepare to do other ops */
632 int init_svc(bool raw);
633 int init_ctl();
634 int init_rados();
635 int init_complete();
636 int initialize();
637 void finalize();
638
639 int register_to_service_map(const string& daemon_type, const map<string, string>& meta);
640 int update_service_map(std::map<std::string, std::string>&& status);
641
642 /// list logs
643 int log_list_init(const string& prefix, RGWAccessHandle *handle);
644 int log_list_next(RGWAccessHandle handle, string *name);
645
646 /// remove log
647 int log_remove(const string& name);
648
649 /// show log
650 int log_show_init(const string& name, RGWAccessHandle *handle);
651 int log_show_next(RGWAccessHandle handle, rgw_log_entry *entry);
652
653 // log bandwidth info
654 int log_usage(map<rgw_user_bucket, RGWUsageBatch>& usage_info);
655 int read_usage(const rgw_user& user, const string& bucket_name, uint64_t start_epoch, uint64_t end_epoch,
656 uint32_t max_entries, bool *is_truncated, RGWUsageIter& read_iter, map<rgw_user_bucket,
657 rgw_usage_log_entry>& usage);
658 int trim_usage(const rgw_user& user, const string& bucket_name, uint64_t start_epoch, uint64_t end_epoch);
659 int clear_usage();
660
661 int create_pool(const rgw_pool& pool);
662
663 void create_bucket_id(string *bucket_id);
664
665 bool get_obj_data_pool(const rgw_placement_rule& placement_rule, const rgw_obj& obj, rgw_pool *pool);
666 bool obj_to_raw(const rgw_placement_rule& placement_rule, const rgw_obj& obj, rgw_raw_obj *raw_obj);
667
668 int create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket,
669 const string& zonegroup_id,
670 const rgw_placement_rule& placement_rule,
671 const string& swift_ver_location,
672 const RGWQuotaInfo * pquota_info,
673 map<std::string,bufferlist>& attrs,
674 RGWBucketInfo& bucket_info,
675 obj_version *pobjv,
676 obj_version *pep_objv,
677 ceph::real_time creation_time,
678 rgw_bucket *master_bucket,
679 uint32_t *master_num_shards,
680 optional_yield y,
681 bool exclusive = true);
682
683 RGWCoroutinesManagerRegistry *get_cr_registry() { return cr_registry; }
684
685 struct BucketShard {
686 RGWRados *store;
687 rgw_bucket bucket;
688 int shard_id;
689 RGWSI_RADOS::Obj bucket_obj;
690
691 explicit BucketShard(RGWRados *_store) : store(_store), shard_id(-1) {}
692 int init(const rgw_bucket& _bucket, const rgw_obj& obj, RGWBucketInfo* out);
693 int init(const rgw_bucket& _bucket, int sid, const rgw::bucket_index_layout_generation& idx_layout, RGWBucketInfo* out);
694 int init(const RGWBucketInfo& bucket_info, const rgw_obj& obj);
695 int init(const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int sid);
696 };
697
698 class Object {
699 RGWRados *store;
700 RGWBucketInfo bucket_info;
701 RGWObjectCtx& ctx;
702 rgw_obj obj;
703
704 BucketShard bs;
705
706 RGWObjState *state;
707
708 bool versioning_disabled;
709
710 bool bs_initialized;
711
712 protected:
713 int get_state(RGWObjState **pstate, bool follow_olh, optional_yield y, bool assume_noent = false);
714 void invalidate_state();
715
716 int prepare_atomic_modification(librados::ObjectWriteOperation& op, bool reset_obj, const string *ptag,
717 const char *ifmatch, const char *ifnomatch, bool removal_op, bool modify_tail, optional_yield y);
718 int complete_atomic_modification();
719
720 public:
721 Object(RGWRados *_store, const RGWBucketInfo& _bucket_info, RGWObjectCtx& _ctx, const rgw_obj& _obj) : store(_store), bucket_info(_bucket_info),
722 ctx(_ctx), obj(_obj), bs(store),
723 state(NULL), versioning_disabled(false),
724 bs_initialized(false) {}
725
726 RGWRados *get_store() { return store; }
727 rgw_obj& get_obj() { return obj; }
728 RGWObjectCtx& get_ctx() { return ctx; }
729 RGWBucketInfo& get_bucket_info() { return bucket_info; }
730 int get_manifest(RGWObjManifest **pmanifest, optional_yield y);
731
732 int get_bucket_shard(BucketShard **pbs) {
733 if (!bs_initialized) {
734 int r =
735 bs.init(bucket_info.bucket, obj, nullptr /* no RGWBucketInfo */);
736 if (r < 0) {
737 return r;
738 }
739 bs_initialized = true;
740 }
741 *pbs = &bs;
742 return 0;
743 }
744
745 void set_versioning_disabled(bool status) {
746 versioning_disabled = status;
747 }
748
749 bool versioning_enabled() {
750 return (!versioning_disabled && bucket_info.versioning_enabled());
751 }
752
753 struct Read {
754 RGWRados::Object *source;
755
756 struct GetObjState {
757 map<rgw_pool, librados::IoCtx> io_ctxs;
758 rgw_pool cur_pool;
759 librados::IoCtx *cur_ioctx{nullptr};
760 rgw_obj obj;
761 rgw_raw_obj head_obj;
762 } state;
763
764 struct ConditionParams {
765 const ceph::real_time *mod_ptr;
766 const ceph::real_time *unmod_ptr;
767 bool high_precision_time;
768 uint32_t mod_zone_id;
769 uint64_t mod_pg_ver;
770 const char *if_match;
771 const char *if_nomatch;
772
773 ConditionParams() :
774 mod_ptr(NULL), unmod_ptr(NULL), high_precision_time(false), mod_zone_id(0), mod_pg_ver(0),
775 if_match(NULL), if_nomatch(NULL) {}
776 } conds;
777
778 struct Params {
779 ceph::real_time *lastmod;
780 uint64_t *obj_size;
781 map<string, bufferlist> *attrs;
782 rgw_obj *target_obj;
783
784 Params() : lastmod(nullptr), obj_size(nullptr), attrs(nullptr),
785 target_obj(nullptr) {}
786 } params;
787
788 explicit Read(RGWRados::Object *_source) : source(_source) {}
789
790 int prepare(optional_yield y);
791 static int range_to_ofs(uint64_t obj_size, int64_t &ofs, int64_t &end);
792 int read(int64_t ofs, int64_t end, bufferlist& bl, optional_yield y);
793 int iterate(int64_t ofs, int64_t end, RGWGetDataCB *cb, optional_yield y);
794 int get_attr(const char *name, bufferlist& dest, optional_yield y);
795 };
796
797 struct Write {
798 RGWRados::Object *target;
799
800 struct MetaParams {
801 ceph::real_time *mtime;
802 map<std::string, bufferlist>* rmattrs;
803 const bufferlist *data;
804 RGWObjManifest *manifest;
805 const string *ptag;
806 list<rgw_obj_index_key> *remove_objs;
807 ceph::real_time set_mtime;
808 rgw_user owner;
809 RGWObjCategory category;
810 int flags;
811 const char *if_match;
812 const char *if_nomatch;
813 std::optional<uint64_t> olh_epoch;
814 ceph::real_time delete_at;
815 bool canceled;
816 const string *user_data;
817 rgw_zone_set *zones_trace;
818 bool modify_tail;
819 bool completeMultipart;
820 bool appendable;
821
822 MetaParams() : mtime(NULL), rmattrs(NULL), data(NULL), manifest(NULL), ptag(NULL),
823 remove_objs(NULL), category(RGWObjCategory::Main), flags(0),
824 if_match(NULL), if_nomatch(NULL), canceled(false), user_data(nullptr), zones_trace(nullptr),
825 modify_tail(false), completeMultipart(false), appendable(false) {}
826 } meta;
827
828 explicit Write(RGWRados::Object *_target) : target(_target) {}
829
830 int _do_write_meta(uint64_t size, uint64_t accounted_size,
831 map<std::string, bufferlist>& attrs,
832 bool modify_tail, bool assume_noent,
833 void *index_op, optional_yield y);
834 int write_meta(uint64_t size, uint64_t accounted_size,
835 map<std::string, bufferlist>& attrs, optional_yield y);
836 int write_data(const char *data, uint64_t ofs, uint64_t len, bool exclusive);
837 const req_state* get_req_state() {
838 return (req_state *)target->get_ctx().get_private();
839 }
840 };
841
842 struct Delete {
843 RGWRados::Object *target;
844
845 struct DeleteParams {
846 rgw_user bucket_owner;
847 int versioning_status;
848 ACLOwner obj_owner; /* needed for creation of deletion marker */
849 uint64_t olh_epoch;
850 string marker_version_id;
851 uint32_t bilog_flags;
852 list<rgw_obj_index_key> *remove_objs;
853 ceph::real_time expiration_time;
854 ceph::real_time unmod_since;
855 ceph::real_time mtime; /* for setting delete marker mtime */
856 bool high_precision_time;
857 rgw_zone_set *zones_trace;
858 bool abortmp;
859 uint64_t parts_accounted_size;
860
861 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) {}
862 } params;
863
864 struct DeleteResult {
865 bool delete_marker;
866 string version_id;
867
868 DeleteResult() : delete_marker(false) {}
869 } result;
870
871 explicit Delete(RGWRados::Object *_target) : target(_target) {}
872
873 int delete_obj(optional_yield y);
874 };
875
876 struct Stat {
877 RGWRados::Object *source;
878
879 struct Result {
880 rgw_obj obj;
881 std::optional<RGWObjManifest> manifest;
882 uint64_t size{0};
883 struct timespec mtime {};
884 map<string, bufferlist> attrs;
885 } result;
886
887 struct State {
888 librados::IoCtx io_ctx;
889 librados::AioCompletion *completion;
890 int ret;
891
892 State() : completion(NULL), ret(0) {}
893 } state;
894
895
896 explicit Stat(RGWRados::Object *_source) : source(_source) {}
897
898 int stat_async();
899 int wait();
900 int stat();
901 private:
902 int finish();
903 };
904 };
905
906 class Bucket {
907 RGWRados *store;
908 RGWBucketInfo bucket_info;
909 rgw_bucket& bucket;
910 int shard_id;
911
912 public:
913 Bucket(RGWRados *_store, const RGWBucketInfo& _bucket_info) : store(_store), bucket_info(_bucket_info), bucket(bucket_info.bucket),
914 shard_id(RGW_NO_SHARD) {}
915 RGWRados *get_store() { return store; }
916 rgw_bucket& get_bucket() { return bucket; }
917 RGWBucketInfo& get_bucket_info() { return bucket_info; }
918
919 int update_bucket_id(const string& new_bucket_id);
920
921 int get_shard_id() { return shard_id; }
922 void set_shard_id(int id) {
923 shard_id = id;
924 }
925
926 class UpdateIndex {
927 RGWRados::Bucket *target;
928 string optag;
929 rgw_obj obj;
930 uint16_t bilog_flags{0};
931 BucketShard bs;
932 bool bs_initialized{false};
933 bool blind;
934 bool prepared{false};
935 rgw_zone_set *zones_trace{nullptr};
936
937 int init_bs() {
938 int r =
939 bs.init(target->get_bucket(), obj, nullptr /* no RGWBucketInfo */);
940 if (r < 0) {
941 return r;
942 }
943 bs_initialized = true;
944 return 0;
945 }
946
947 void invalidate_bs() {
948 bs_initialized = false;
949 }
950
951 int guard_reshard(BucketShard **pbs, std::function<int(BucketShard *)> call);
952 public:
953
954 UpdateIndex(RGWRados::Bucket *_target, const rgw_obj& _obj) : target(_target), obj(_obj),
955 bs(target->get_store()) {
956 blind = (target->get_bucket_info().layout.current_index.layout.type == rgw::BucketIndexType::Indexless);
957 }
958
959 int get_bucket_shard(BucketShard **pbs) {
960 if (!bs_initialized) {
961 int r = init_bs();
962 if (r < 0) {
963 return r;
964 }
965 }
966 *pbs = &bs;
967 return 0;
968 }
969
970 void set_bilog_flags(uint16_t flags) {
971 bilog_flags = flags;
972 }
973
974 void set_zones_trace(rgw_zone_set *_zones_trace) {
975 zones_trace = _zones_trace;
976 }
977
978 int prepare(RGWModifyOp, const string *write_tag, optional_yield y);
979 int complete(int64_t poolid, uint64_t epoch, uint64_t size,
980 uint64_t accounted_size, ceph::real_time& ut,
981 const string& etag, const string& content_type,
982 const string& storage_class,
983 bufferlist *acl_bl, RGWObjCategory category,
984 list<rgw_obj_index_key> *remove_objs, const string *user_data = nullptr, bool appendable = false);
985 int complete_del(int64_t poolid, uint64_t epoch,
986 ceph::real_time& removed_mtime, /* mtime of removed object */
987 list<rgw_obj_index_key> *remove_objs);
988 int cancel();
989
990 const string *get_optag() { return &optag; }
991
992 bool is_prepared() { return prepared; }
993 }; // class UpdateIndex
994
995 class List {
996 protected:
997 // absolute maximum number of objects that
998 // list_objects_(un)ordered can return
999 static constexpr int64_t bucket_list_objects_absolute_max = 25000;
1000
1001 RGWRados::Bucket *target;
1002 rgw_obj_key next_marker;
1003
1004 int list_objects_ordered(int64_t max,
1005 vector<rgw_bucket_dir_entry> *result,
1006 map<string, bool> *common_prefixes,
1007 bool *is_truncated,
1008 optional_yield y);
1009 int list_objects_unordered(int64_t max,
1010 vector<rgw_bucket_dir_entry> *result,
1011 map<string, bool> *common_prefixes,
1012 bool *is_truncated,
1013 optional_yield y);
1014
1015 public:
1016
1017 struct Params {
1018 string prefix;
1019 string delim;
1020 rgw_obj_key marker;
1021 rgw_obj_key end_marker;
1022 string ns;
1023 bool enforce_ns;
1024 RGWAccessListFilter *filter;
1025 bool list_versions;
1026 bool allow_unordered;
1027
1028 Params() :
1029 enforce_ns(true),
1030 filter(NULL),
1031 list_versions(false),
1032 allow_unordered(false)
1033 {}
1034 } params;
1035
1036 explicit List(RGWRados::Bucket *_target) : target(_target) {}
1037
1038 int list_objects(int64_t max,
1039 vector<rgw_bucket_dir_entry> *result,
1040 map<string, bool> *common_prefixes,
1041 bool *is_truncated,
1042 optional_yield y) {
1043 if (params.allow_unordered) {
1044 return list_objects_unordered(max, result, common_prefixes,
1045 is_truncated, y);
1046 } else {
1047 return list_objects_ordered(max, result, common_prefixes,
1048 is_truncated, y);
1049 }
1050 }
1051 rgw_obj_key& get_next_marker() {
1052 return next_marker;
1053 }
1054 }; // class List
1055 }; // class Bucket
1056
1057 int on_last_entry_in_listing(RGWBucketInfo& bucket_info,
1058 const std::string& obj_prefix,
1059 const std::string& obj_delim,
1060 std::function<int(const rgw_bucket_dir_entry&)> handler);
1061
1062 bool swift_versioning_enabled(rgw::sal::RGWBucket* bucket) const;
1063
1064 int swift_versioning_copy(RGWObjectCtx& obj_ctx, /* in/out */
1065 const rgw_user& user, /* in */
1066 rgw::sal::RGWBucket* bucket, /* in */
1067 rgw::sal::RGWObject* obj, /* in */
1068 const DoutPrefixProvider *dpp, /* in/out */
1069 optional_yield y); /* in */
1070 int swift_versioning_restore(RGWObjectCtx& obj_ctx, /* in/out */
1071 const rgw_user& user, /* in */
1072 rgw::sal::RGWBucket* bucket, /* in */
1073 rgw::sal::RGWObject* obj, /* in */
1074 bool& restored, /* out */
1075 const DoutPrefixProvider *dpp); /* in/out */
1076 int copy_obj_to_remote_dest(RGWObjState *astate,
1077 map<string, bufferlist>& src_attrs,
1078 RGWRados::Object::Read& read_op,
1079 const rgw_user& user_id,
1080 rgw::sal::RGWObject* dest_obj,
1081 ceph::real_time *mtime);
1082
1083 enum AttrsMod {
1084 ATTRSMOD_NONE = 0,
1085 ATTRSMOD_REPLACE = 1,
1086 ATTRSMOD_MERGE = 2
1087 };
1088
1089 int rewrite_obj(RGWBucketInfo& dest_bucket_info, rgw::sal::RGWObject* obj, const DoutPrefixProvider *dpp, optional_yield y);
1090
1091 int stat_remote_obj(RGWObjectCtx& obj_ctx,
1092 const rgw_user& user_id,
1093 req_info *info,
1094 const rgw_zone_id& source_zone,
1095 rgw::sal::RGWObject* src_obj,
1096 const RGWBucketInfo *src_bucket_info,
1097 real_time *src_mtime,
1098 uint64_t *psize,
1099 const real_time *mod_ptr,
1100 const real_time *unmod_ptr,
1101 bool high_precision_time,
1102 const char *if_match,
1103 const char *if_nomatch,
1104 map<string, bufferlist> *pattrs,
1105 map<string, string> *pheaders,
1106 string *version_id,
1107 string *ptag,
1108 string *petag);
1109
1110 int fetch_remote_obj(RGWObjectCtx& obj_ctx,
1111 const rgw_user& user_id,
1112 req_info *info,
1113 const rgw_zone_id& source_zone,
1114 rgw::sal::RGWObject* dest_obj,
1115 rgw::sal::RGWObject* src_obj,
1116 rgw::sal::RGWBucket* dest_bucket,
1117 rgw::sal::RGWBucket* src_bucket,
1118 std::optional<rgw_placement_rule> dest_placement,
1119 ceph::real_time *src_mtime,
1120 ceph::real_time *mtime,
1121 const ceph::real_time *mod_ptr,
1122 const ceph::real_time *unmod_ptr,
1123 bool high_precision_time,
1124 const char *if_match,
1125 const char *if_nomatch,
1126 AttrsMod attrs_mod,
1127 bool copy_if_newer,
1128 rgw::sal::RGWAttrs& attrs,
1129 RGWObjCategory category,
1130 std::optional<uint64_t> olh_epoch,
1131 ceph::real_time delete_at,
1132 string *ptag,
1133 string *petag,
1134 void (*progress_cb)(off_t, void *),
1135 void *progress_data,
1136 const DoutPrefixProvider *dpp,
1137 RGWFetchObjFilter *filter,
1138 rgw_zone_set *zones_trace= nullptr,
1139 std::optional<uint64_t>* bytes_transferred = 0);
1140 /**
1141 * Copy an object.
1142 * dest_obj: the object to copy into
1143 * src_obj: the object to copy from
1144 * attrs: usage depends on attrs_mod parameter
1145 * attrs_mod: the modification mode of the attrs, may have the following values:
1146 * ATTRSMOD_NONE - the attributes of the source object will be
1147 * copied without modifications, attrs parameter is ignored;
1148 * ATTRSMOD_REPLACE - new object will have the attributes provided by attrs
1149 * parameter, source object attributes are not copied;
1150 * ATTRSMOD_MERGE - any conflicting meta keys on the source object's attributes
1151 * are overwritten by values contained in attrs parameter.
1152 * Returns: 0 on success, -ERR# otherwise.
1153 */
1154 int copy_obj(RGWObjectCtx& obj_ctx,
1155 const rgw_user& user_id,
1156 req_info *info,
1157 const rgw_zone_id& source_zone,
1158 rgw::sal::RGWObject* dest_obj,
1159 rgw::sal::RGWObject* src_obj,
1160 rgw::sal::RGWBucket* dest_bucket,
1161 rgw::sal::RGWBucket* src_bucket,
1162 const rgw_placement_rule& dest_placement,
1163 ceph::real_time *src_mtime,
1164 ceph::real_time *mtime,
1165 const ceph::real_time *mod_ptr,
1166 const ceph::real_time *unmod_ptr,
1167 bool high_precision_time,
1168 const char *if_match,
1169 const char *if_nomatch,
1170 AttrsMod attrs_mod,
1171 bool copy_if_newer,
1172 map<std::string, bufferlist>& attrs,
1173 RGWObjCategory category,
1174 uint64_t olh_epoch,
1175 ceph::real_time delete_at,
1176 string *version_id,
1177 string *ptag,
1178 string *petag,
1179 void (*progress_cb)(off_t, void *),
1180 void *progress_data,
1181 const DoutPrefixProvider *dpp,
1182 optional_yield y);
1183
1184 int copy_obj_data(RGWObjectCtx& obj_ctx,
1185 rgw::sal::RGWBucket* bucket,
1186 const rgw_placement_rule& dest_placement,
1187 RGWRados::Object::Read& read_op, off_t end,
1188 rgw::sal::RGWObject* dest_obj,
1189 ceph::real_time *mtime,
1190 ceph::real_time set_mtime,
1191 map<string, bufferlist>& attrs,
1192 uint64_t olh_epoch,
1193 ceph::real_time delete_at,
1194 string *petag,
1195 const DoutPrefixProvider *dpp,
1196 optional_yield y);
1197
1198 int transition_obj(RGWObjectCtx& obj_ctx,
1199 rgw::sal::RGWBucket* bucket,
1200 rgw::sal::RGWObject& obj,
1201 const rgw_placement_rule& placement_rule,
1202 const real_time& mtime,
1203 uint64_t olh_epoch,
1204 const DoutPrefixProvider *dpp,
1205 optional_yield y);
1206
1207 int check_bucket_empty(RGWBucketInfo& bucket_info, optional_yield y);
1208
1209 /**
1210 * Delete a bucket.
1211 * bucket: the name of the bucket to delete
1212 * Returns 0 on success, -ERR# otherwise.
1213 */
1214 int delete_bucket(RGWBucketInfo& bucket_info, RGWObjVersionTracker& objv_tracker, optional_yield y, bool check_empty = true);
1215
1216 void wakeup_meta_sync_shards(set<int>& shard_ids);
1217 void wakeup_data_sync_shards(const rgw_zone_id& source_zone, map<int, set<string> >& shard_ids);
1218
1219 RGWMetaSyncStatusManager* get_meta_sync_manager();
1220 RGWDataSyncStatusManager* get_data_sync_manager(const rgw_zone_id& source_zone);
1221
1222 int set_bucket_owner(rgw_bucket& bucket, ACLOwner& owner);
1223 int set_buckets_enabled(std::vector<rgw_bucket>& buckets, bool enabled);
1224 int bucket_suspended(rgw_bucket& bucket, bool *suspended);
1225
1226 /** Delete an object.*/
1227 int delete_obj(RGWObjectCtx& obj_ctx,
1228 const RGWBucketInfo& bucket_owner,
1229 const rgw_obj& src_obj,
1230 int versioning_status,
1231 uint16_t bilog_flags = 0,
1232 const ceph::real_time& expiration_time = ceph::real_time(),
1233 rgw_zone_set *zones_trace = nullptr);
1234
1235 int delete_raw_obj(const rgw_raw_obj& obj);
1236
1237 /** Remove an object from the bucket index */
1238 int delete_obj_index(const rgw_obj& obj, ceph::real_time mtime);
1239
1240 /**
1241 * Set an attr on an object.
1242 * bucket: name of the bucket holding the object
1243 * obj: name of the object to set the attr on
1244 * name: the attr to set
1245 * bl: the contents of the attr
1246 * Returns: 0 on success, -ERR# otherwise.
1247 */
1248 int set_attr(void *ctx, const RGWBucketInfo& bucket_info, rgw_obj& obj, const char *name, bufferlist& bl);
1249
1250 int set_attrs(void *ctx, const RGWBucketInfo& bucket_info, rgw_obj& obj,
1251 map<string, bufferlist>& attrs,
1252 map<string, bufferlist>* rmattrs,
1253 optional_yield y);
1254
1255 int get_obj_state(RGWObjectCtx *rctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWObjState **state,
1256 bool follow_olh, optional_yield y, bool assume_noent = false);
1257 int get_obj_state(RGWObjectCtx *rctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWObjState **state, optional_yield y) {
1258 return get_obj_state(rctx, bucket_info, obj, state, true, y);
1259 }
1260
1261 using iterate_obj_cb = int (*)(const rgw_raw_obj&, off_t, off_t,
1262 off_t, bool, RGWObjState*, void*);
1263
1264 int iterate_obj(RGWObjectCtx& ctx, const RGWBucketInfo& bucket_info,
1265 const rgw_obj& obj, off_t ofs, off_t end,
1266 uint64_t max_chunk_size, iterate_obj_cb cb, void *arg,
1267 optional_yield y);
1268
1269 int get_obj_iterate_cb(const rgw_raw_obj& read_obj, off_t obj_ofs,
1270 off_t read_ofs, off_t len, bool is_head_obj,
1271 RGWObjState *astate, void *arg);
1272
1273 void get_obj_aio_completion_cb(librados::completion_t cb, void *arg);
1274
1275 /**
1276 * a simple object read without keeping state
1277 */
1278
1279 int raw_obj_stat(rgw_raw_obj& obj, uint64_t *psize, ceph::real_time *pmtime, uint64_t *epoch,
1280 map<string, bufferlist> *attrs, bufferlist *first_chunk,
1281 RGWObjVersionTracker *objv_tracker, optional_yield y);
1282
1283 int obj_operate(const RGWBucketInfo& bucket_info, const rgw_obj& obj, librados::ObjectWriteOperation *op);
1284 int obj_operate(const RGWBucketInfo& bucket_info, const rgw_obj& obj, librados::ObjectReadOperation *op);
1285
1286 int guard_reshard(BucketShard *bs,
1287 const rgw_obj& obj_instance,
1288 const RGWBucketInfo& bucket_info,
1289 std::function<int(BucketShard *)> call);
1290 int block_while_resharding(RGWRados::BucketShard *bs,
1291 string *new_bucket_id,
1292 const RGWBucketInfo& bucket_info,
1293 optional_yield y);
1294
1295 void bucket_index_guard_olh_op(RGWObjState& olh_state, librados::ObjectOperation& op);
1296 int olh_init_modification(const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, string *op_tag);
1297 int olh_init_modification_impl(const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, string *op_tag);
1298 int bucket_index_link_olh(const RGWBucketInfo& bucket_info, RGWObjState& olh_state,
1299 const rgw_obj& obj_instance, bool delete_marker,
1300 const string& op_tag, struct rgw_bucket_dir_entry_meta *meta,
1301 uint64_t olh_epoch,
1302 ceph::real_time unmod_since, bool high_precision_time,
1303 rgw_zone_set *zones_trace = nullptr,
1304 bool log_data_change = false);
1305 int bucket_index_unlink_instance(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);
1306 int bucket_index_read_olh_log(const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& obj_instance, uint64_t ver_marker,
1307 map<uint64_t, vector<rgw_bucket_olh_log_entry> > *log, bool *is_truncated);
1308 int bucket_index_trim_olh_log(const RGWBucketInfo& bucket_info, RGWObjState& obj_state, const rgw_obj& obj_instance, uint64_t ver);
1309 int bucket_index_clear_olh(const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& obj_instance);
1310 int apply_olh_log(RGWObjectCtx& ctx, RGWObjState& obj_state, const RGWBucketInfo& bucket_info, const rgw_obj& obj,
1311 bufferlist& obj_tag, map<uint64_t, vector<rgw_bucket_olh_log_entry> >& log,
1312 uint64_t *plast_ver, rgw_zone_set *zones_trace = nullptr);
1313 int update_olh(RGWObjectCtx& obj_ctx, RGWObjState *state, const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_zone_set *zones_trace = nullptr);
1314 int set_olh(RGWObjectCtx& obj_ctx, const RGWBucketInfo& bucket_info, const rgw_obj& target_obj, bool delete_marker, rgw_bucket_dir_entry_meta *meta,
1315 uint64_t olh_epoch, ceph::real_time unmod_since, bool high_precision_time,
1316 optional_yield y, rgw_zone_set *zones_trace = nullptr, bool log_data_change = false);
1317 int repair_olh(RGWObjState* state, const RGWBucketInfo& bucket_info,
1318 const rgw_obj& obj);
1319 int unlink_obj_instance(RGWObjectCtx& obj_ctx, RGWBucketInfo& bucket_info, const rgw_obj& target_obj,
1320 uint64_t olh_epoch, optional_yield y, rgw_zone_set *zones_trace = nullptr);
1321
1322 void check_pending_olh_entries(map<string, bufferlist>& pending_entries, map<string, bufferlist> *rm_pending_entries);
1323 int remove_olh_pending_entries(const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, map<string, bufferlist>& pending_attrs);
1324 int follow_olh(const RGWBucketInfo& bucket_info, RGWObjectCtx& ctx, RGWObjState *state, const rgw_obj& olh_obj, rgw_obj *target);
1325 int get_olh(const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWOLHInfo *olh);
1326
1327 void gen_rand_obj_instance_name(rgw_obj_key *target_key);
1328 void gen_rand_obj_instance_name(rgw_obj *target);
1329
1330 int update_containers_stats(map<string, RGWBucketEnt>& m);
1331 int append_async(rgw_raw_obj& obj, size_t size, bufferlist& bl);
1332
1333 public:
1334 void set_atomic(void *ctx, rgw_obj& obj) {
1335 RGWObjectCtx *rctx = static_cast<RGWObjectCtx *>(ctx);
1336 rctx->set_atomic(obj);
1337 }
1338 void set_prefetch_data(void *ctx, const rgw_obj& obj) {
1339 RGWObjectCtx *rctx = static_cast<RGWObjectCtx *>(ctx);
1340 rctx->set_prefetch_data(obj);
1341 }
1342 int decode_policy(bufferlist& bl, ACLOwner *owner);
1343 int get_bucket_stats(RGWBucketInfo& bucket_info, int shard_id, string *bucket_ver, string *master_ver,
1344 map<RGWObjCategory, RGWStorageStats>& stats, string *max_marker, bool* syncstopped = NULL);
1345 int get_bucket_stats_async(RGWBucketInfo& bucket_info, int shard_id, RGWGetBucketStats_CB *cb);
1346
1347 int put_bucket_instance_info(RGWBucketInfo& info, bool exclusive, ceph::real_time mtime, map<string, bufferlist> *pattrs);
1348 /* xxx dang obj_ctx -> svc */
1349 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);
1350 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);
1351
1352 static void make_bucket_entry_name(const string& tenant_name, const string& bucket_name, string& bucket_entry);
1353
1354 int get_bucket_info(RGWServices *svc,
1355 const string& tenant_name, const string& bucket_name,
1356 RGWBucketInfo& info,
1357 ceph::real_time *pmtime, optional_yield y, map<string, bufferlist> *pattrs = NULL);
1358
1359 // Returns 0 on successful refresh. Returns error code if there was
1360 // an error or the version stored on the OSD is the same as that
1361 // presented in the BucketInfo structure.
1362 //
1363 int try_refresh_bucket_info(RGWBucketInfo& info,
1364 ceph::real_time *pmtime,
1365 map<string, bufferlist> *pattrs = nullptr);
1366
1367 int put_linked_bucket_info(RGWBucketInfo& info, bool exclusive, ceph::real_time mtime, obj_version *pep_objv,
1368 map<string, bufferlist> *pattrs, bool create_entry_point);
1369
1370 int cls_obj_prepare_op(BucketShard& bs, RGWModifyOp op, string& tag, rgw_obj& obj, uint16_t bilog_flags, optional_yield y, rgw_zone_set *zones_trace = nullptr);
1371 int cls_obj_complete_op(BucketShard& bs, const rgw_obj& obj, RGWModifyOp op, string& tag, int64_t pool, uint64_t epoch,
1372 rgw_bucket_dir_entry& ent, RGWObjCategory category, list<rgw_obj_index_key> *remove_objs, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
1373 int cls_obj_complete_add(BucketShard& bs, const rgw_obj& obj, string& tag, int64_t pool, uint64_t epoch, rgw_bucket_dir_entry& ent,
1374 RGWObjCategory category, list<rgw_obj_index_key> *remove_objs, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
1375 int cls_obj_complete_del(BucketShard& bs, string& tag, int64_t pool, uint64_t epoch, rgw_obj& obj,
1376 ceph::real_time& removed_mtime, list<rgw_obj_index_key> *remove_objs, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
1377 int cls_obj_complete_cancel(BucketShard& bs, string& tag, rgw_obj& obj, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
1378 int cls_obj_set_bucket_tag_timeout(RGWBucketInfo& bucket_info, uint64_t timeout);
1379
1380 using ent_map_t =
1381 boost::container::flat_map<std::string, rgw_bucket_dir_entry>;
1382
1383 using check_filter_t = bool (*)(const std::string&);
1384
1385 int cls_bucket_list_ordered(RGWBucketInfo& bucket_info,
1386 const int shard_id,
1387 const rgw_obj_index_key& start_after,
1388 const string& prefix,
1389 const string& delimiter,
1390 const uint32_t num_entries,
1391 const bool list_versions,
1392 const uint16_t exp_factor, // 0 means ignore
1393 ent_map_t& m,
1394 bool* is_truncated,
1395 bool* cls_filtered,
1396 rgw_obj_index_key *last_entry,
1397 optional_yield y,
1398 check_filter_t force_check_filter = nullptr);
1399 int cls_bucket_list_unordered(RGWBucketInfo& bucket_info,
1400 int shard_id,
1401 const rgw_obj_index_key& start_after,
1402 const string& prefix,
1403 uint32_t num_entries,
1404 bool list_versions,
1405 vector<rgw_bucket_dir_entry>& ent_list,
1406 bool *is_truncated,
1407 rgw_obj_index_key *last_entry,
1408 optional_yield y,
1409 check_filter_t = nullptr);
1410 int cls_bucket_head(const RGWBucketInfo& bucket_info, int shard_id, vector<rgw_bucket_dir_header>& headers, map<int, string> *bucket_instance_ids = NULL);
1411 int cls_bucket_head_async(const RGWBucketInfo& bucket_info, int shard_id, RGWGetDirHeader_CB *ctx, int *num_aio);
1412
1413 int bi_get_instance(const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_bucket_dir_entry *dirent);
1414 int bi_get_olh(const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_bucket_olh_entry *olh);
1415 int bi_get(const RGWBucketInfo& bucket_info, const rgw_obj& obj, BIIndexType index_type, rgw_cls_bi_entry *entry);
1416 void bi_put(librados::ObjectWriteOperation& op, BucketShard& bs, rgw_cls_bi_entry& entry);
1417 int bi_put(BucketShard& bs, rgw_cls_bi_entry& entry);
1418 int bi_put(rgw_bucket& bucket, rgw_obj& obj, rgw_cls_bi_entry& entry);
1419 int bi_list(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);
1420 int bi_list(BucketShard& bs, const string& filter_obj, const string& marker, uint32_t max, list<rgw_cls_bi_entry> *entries, bool *is_truncated);
1421 int bi_list(rgw_bucket& bucket, const string& obj_name, const string& marker, uint32_t max,
1422 list<rgw_cls_bi_entry> *entries, bool *is_truncated);
1423 int bi_remove(BucketShard& bs);
1424
1425 int cls_obj_usage_log_add(const string& oid, rgw_usage_log_info& info);
1426 int cls_obj_usage_log_read(const string& oid, const string& user, const string& bucket, uint64_t start_epoch,
1427 uint64_t end_epoch, uint32_t max_entries, string& read_iter, map<rgw_user_bucket,
1428 rgw_usage_log_entry>& usage, bool *is_truncated);
1429 int cls_obj_usage_log_trim(const string& oid, const string& user, const string& bucket, uint64_t start_epoch,
1430 uint64_t end_epoch);
1431 int cls_obj_usage_log_clear(string& oid);
1432
1433 int get_target_shard_id(const rgw::bucket_index_normal_layout& layout, const string& obj_key, int *shard_id);
1434
1435 int lock_exclusive(const rgw_pool& pool, const string& oid, ceph::timespan& duration, rgw_zone_id& zone_id, string& owner_id);
1436 int unlock(const rgw_pool& pool, const string& oid, rgw_zone_id& zone_id, string& owner_id);
1437
1438 void update_gc_chain(rgw_obj& head_obj, RGWObjManifest& manifest, cls_rgw_obj_chain *chain);
1439 int send_chain_to_gc(cls_rgw_obj_chain& chain, const string& tag);
1440 void delete_objs_inline(cls_rgw_obj_chain& chain, const string& tag);
1441 int gc_operate(string& oid, librados::ObjectWriteOperation *op);
1442 int gc_aio_operate(const std::string& oid, librados::AioCompletion *c,
1443 librados::ObjectWriteOperation *op);
1444 int gc_operate(string& oid, librados::ObjectReadOperation *op, bufferlist *pbl);
1445
1446 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);
1447 int process_gc(bool expired_only);
1448 bool process_expire_objects();
1449 int defer_gc(void *ctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, optional_yield y);
1450
1451 int process_lc();
1452 int list_lc_progress(string& marker, uint32_t max_entries,
1453 vector<rgw::sal::Lifecycle::LCEntry>& progress_map, int& index);
1454
1455 int bucket_check_index(RGWBucketInfo& bucket_info,
1456 map<RGWObjCategory, RGWStorageStats> *existing_stats,
1457 map<RGWObjCategory, RGWStorageStats> *calculated_stats);
1458 int bucket_rebuild_index(RGWBucketInfo& bucket_info);
1459 int bucket_set_reshard(const RGWBucketInfo& bucket_info, const cls_rgw_bucket_instance_entry& entry);
1460 int remove_objs_from_index(RGWBucketInfo& bucket_info, list<rgw_obj_index_key>& oid_list);
1461 int move_rados_obj(librados::IoCtx& src_ioctx,
1462 const string& src_oid, const string& src_locator,
1463 librados::IoCtx& dst_ioctx,
1464 const string& dst_oid, const string& dst_locator);
1465 int fix_head_obj_locator(const RGWBucketInfo& bucket_info, bool copy_obj, bool remove_bad, rgw_obj_key& key);
1466 int fix_tail_obj_locator(const RGWBucketInfo& bucket_info, rgw_obj_key& key, bool fix, bool *need_fix, optional_yield y);
1467
1468 int check_quota(const rgw_user& bucket_owner, rgw_bucket& bucket,
1469 RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota, uint64_t obj_size,
1470 optional_yield y, bool check_size_only = false);
1471
1472 int check_bucket_shards(const RGWBucketInfo& bucket_info, const rgw_bucket& bucket,
1473 uint64_t num_objs);
1474
1475 int add_bucket_to_reshard(const RGWBucketInfo& bucket_info, uint32_t new_num_shards);
1476
1477 uint64_t instance_id();
1478
1479 librados::Rados* get_rados_handle();
1480
1481 int delete_raw_obj_aio(const rgw_raw_obj& obj, list<librados::AioCompletion *>& handles);
1482 int delete_obj_aio(const rgw_obj& obj, RGWBucketInfo& info, RGWObjState *astate,
1483 list<librados::AioCompletion *>& handles, bool keep_index_consistent,
1484 optional_yield y);
1485
1486 private:
1487 /**
1488 * Check the actual on-disk state of the object specified
1489 * by list_state, and fill in the time and size of object.
1490 * Then append any changes to suggested_updates for
1491 * the rgw class' dir_suggest_changes function.
1492 *
1493 * Note that this can maul list_state; don't use it afterwards. Also
1494 * it expects object to already be filled in from list_state; it only
1495 * sets the size and mtime.
1496 *
1497 * Returns 0 on success, -ENOENT if the object doesn't exist on disk,
1498 * and -errno on other failures. (-ENOENT is not a failure, and it
1499 * will encode that info as a suggested update.)
1500 */
1501 int check_disk_state(librados::IoCtx io_ctx,
1502 const RGWBucketInfo& bucket_info,
1503 rgw_bucket_dir_entry& list_state,
1504 rgw_bucket_dir_entry& object,
1505 bufferlist& suggested_updates,
1506 optional_yield y);
1507
1508 /**
1509 * Init pool iteration
1510 * pool: pool to use for the ctx initialization
1511 * ctx: context object to use for the iteration
1512 * Returns: 0 on success, -ERR# otherwise.
1513 */
1514 int pool_iterate_begin(const rgw_pool& pool, RGWPoolIterCtx& ctx);
1515
1516 /**
1517 * Init pool iteration
1518 * pool: pool to use
1519 * cursor: position to start iteration
1520 * ctx: context object to use for the iteration
1521 * Returns: 0 on success, -ERR# otherwise.
1522 */
1523 int pool_iterate_begin(const rgw_pool& pool, const string& cursor, RGWPoolIterCtx& ctx);
1524
1525 /**
1526 * Get pool iteration position
1527 * ctx: context object to use for the iteration
1528 * Returns: string representation of position
1529 */
1530 string pool_iterate_get_cursor(RGWPoolIterCtx& ctx);
1531
1532 /**
1533 * Iterate over pool return object names, use optional filter
1534 * ctx: iteration context, initialized with pool_iterate_begin()
1535 * num: max number of objects to return
1536 * objs: a vector that the results will append into
1537 * is_truncated: if not NULL, will hold true iff iteration is complete
1538 * filter: if not NULL, will be used to filter returned objects
1539 * Returns: 0 on success, -ERR# otherwise.
1540 */
1541 int pool_iterate(RGWPoolIterCtx& ctx, uint32_t num, vector<rgw_bucket_dir_entry>& objs,
1542 bool *is_truncated, RGWAccessListFilter *filter);
1543
1544 uint64_t next_bucket_id();
1545
1546 /**
1547 * This is broken out to facilitate unit testing.
1548 */
1549 static uint32_t calc_ordered_bucket_list_per_shard(uint32_t num_entries,
1550 uint32_t num_shards);
1551 };
1552
1553 #endif