1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #ifndef CEPH_RGWRADOS_H
5 #define CEPH_RGWRADOS_H
8 #include <boost/container/flat_map.hpp>
10 #include "include/rados/librados.hpp"
11 #include "include/Context.h"
12 #include "include/random.h"
13 #include "common/RefCountedObj.h"
14 #include "common/ceph_time.h"
15 #include "common/Timer.h"
16 #include "rgw_common.h"
17 #include "cls/rgw/cls_rgw_types.h"
18 #include "cls/version/cls_version_types.h"
19 #include "cls/log/cls_log_types.h"
20 #include "cls/timeindex/cls_timeindex_types.h"
21 #include "cls/otp/cls_otp_types.h"
23 #include "rgw_metadata.h"
24 #include "rgw_meta_sync_status.h"
25 #include "rgw_period_puller.h"
26 #include "rgw_obj_manifest.h"
27 #include "rgw_sync_module.h"
28 #include "rgw_trim_bilog.h"
29 #include "rgw_service.h"
32 #include "rgw_d3n_cacherequest.h"
34 #include "services/svc_rados.h"
35 #include "services/svc_bi_rados.h"
36 #include "common/Throttle.h"
37 #include "common/ceph_mutex.h"
38 #include "rgw_cache.h"
45 class RGWMetaNotifier
;
46 class RGWDataNotifier
;
48 class RGWObjectExpirer
;
49 class RGWMetaSyncProcessorThread
;
50 class RGWDataSyncProcessorThread
;
51 class RGWSyncLogTrimThread
;
52 class RGWSyncTraceManager
;
58 class RGWSysObjectCtx
;
61 /* flags for put_obj_meta() */
62 #define PUT_OBJ_CREATE 0x01
63 #define PUT_OBJ_EXCL 0x02
64 #define PUT_OBJ_CREATE_EXCL (PUT_OBJ_CREATE | PUT_OBJ_EXCL)
66 #define RGW_OBJ_NS_MULTIPART "multipart"
67 #define RGW_OBJ_NS_SHADOW "shadow"
69 static inline void prepend_bucket_marker(const rgw_bucket
& bucket
, const std::string
& orig_oid
, std::string
& oid
)
71 if (bucket
.marker
.empty() || orig_oid
.empty()) {
80 static inline void get_obj_bucket_and_oid_loc(const rgw_obj
& obj
, std::string
& oid
, std::string
& locator
)
82 const rgw_bucket
& bucket
= obj
.bucket
;
83 prepend_bucket_marker(bucket
, obj
.get_oid(), oid
);
84 const std::string
& loc
= obj
.key
.get_loc();
86 prepend_bucket_marker(bucket
, loc
, locator
);
92 int rgw_policy_from_attrset(const DoutPrefixProvider
*dpp
,
94 std::map
<std::string
, bufferlist
>& attrset
,
95 RGWAccessControlPolicy
*policy
);
101 RGWOLHInfo() : removed(false) {}
103 void encode(bufferlist
& bl
) const {
104 ENCODE_START(1, 1, bl
);
110 void decode(bufferlist::const_iterator
& bl
) {
116 static void generate_test_instances(std::list
<RGWOLHInfo
*>& o
);
117 void dump(Formatter
*f
) const;
119 WRITE_CLASS_ENCODER(RGWOLHInfo
)
121 struct RGWOLHPendingInfo
{
122 ceph::real_time time
;
124 RGWOLHPendingInfo() {}
126 void encode(bufferlist
& bl
) const {
127 ENCODE_START(1, 1, bl
);
132 void decode(bufferlist::const_iterator
& bl
) {
138 void dump(Formatter
*f
) const;
140 WRITE_CLASS_ENCODER(RGWOLHPendingInfo
)
142 struct RGWUsageBatch
{
143 std::map
<ceph::real_time
, rgw_usage_log_entry
> m
;
145 void insert(ceph::real_time
& t
, rgw_usage_log_entry
& entry
, bool *account
) {
146 bool exists
= m
.find(t
) != m
.end();
148 m
[t
].aggregate(entry
);
152 struct RGWCloneRangeInfo
{
159 class RGWFetchObjFilter
{
161 virtual ~RGWFetchObjFilter() {}
163 virtual int filter(CephContext
*cct
,
164 const rgw_obj_key
& source_key
,
165 const RGWBucketInfo
& dest_bucket_info
,
166 std::optional
<rgw_placement_rule
> dest_placement_rule
,
167 const std::map
<std::string
, bufferlist
>& obj_attrs
,
168 std::optional
<rgw_user
> *poverride_owner
,
169 const rgw_placement_rule
**prule
) = 0;
172 class RGWFetchObjFilter_Default
: public RGWFetchObjFilter
{
174 rgw_placement_rule dest_rule
;
176 RGWFetchObjFilter_Default() {}
178 int filter(CephContext
*cct
,
179 const rgw_obj_key
& source_key
,
180 const RGWBucketInfo
& dest_bucket_info
,
181 std::optional
<rgw_placement_rule
> dest_placement_rule
,
182 const std::map
<std::string
, bufferlist
>& obj_attrs
,
183 std::optional
<rgw_user
> *poverride_owner
,
184 const rgw_placement_rule
**prule
) override
;
188 rgw::sal::Store
* store
;
189 ceph::shared_mutex lock
= ceph::make_shared_mutex("RGWObjectCtx");
192 std::map
<rgw_obj
, RGWObjState
> objs_state
;
194 explicit RGWObjectCtx(rgw::sal::Store
* _store
) : store(_store
) {}
195 explicit RGWObjectCtx(rgw::sal::Store
* _store
, void *_s
) : store(_store
), s(_s
) {}
197 void *get_private() {
201 rgw::sal::Store
* get_store() {
205 RGWObjState
*get_state(const rgw_obj
& obj
);
207 void set_compressed(const rgw_obj
& obj
);
208 void set_atomic(rgw_obj
& obj
);
209 void set_prefetch_data(const rgw_obj
& obj
);
210 void invalidate(const rgw_obj
& obj
);
214 struct RGWRawObjState
{
216 bool has_attrs
{false};
219 ceph::real_time mtime
;
222 bool has_data
{false};
224 bool prefetch_data
{false};
227 /* important! don't forget to update copy constructor */
229 RGWObjVersionTracker objv_tracker
;
231 std::map
<std::string
, bufferlist
> attrset
;
233 RGWRawObjState(const RGWRawObjState
& rhs
) : obj (rhs
.obj
) {
234 has_attrs
= rhs
.has_attrs
;
239 if (rhs
.obj_tag
.length()) {
240 obj_tag
= rhs
.obj_tag
;
242 has_data
= rhs
.has_data
;
243 if (rhs
.data
.length()) {
246 prefetch_data
= rhs
.prefetch_data
;
248 objv_tracker
= rhs
.objv_tracker
;
252 struct RGWPoolIterCtx
{
253 librados::IoCtx io_ctx
;
254 librados::NObjectIterator iter
;
257 struct RGWListRawObjsCtx
{
259 RGWPoolIterCtx iter_ctx
;
261 RGWListRawObjsCtx() : initialized(false) {}
264 struct objexp_hint_entry
{
266 std::string bucket_name
;
267 std::string bucket_id
;
269 ceph::real_time exp_time
;
271 void encode(bufferlist
& bl
) const {
272 ENCODE_START(2, 1, bl
);
273 encode(bucket_name
, bl
);
274 encode(bucket_id
, bl
);
276 encode(exp_time
, bl
);
281 void decode(bufferlist::const_iterator
& bl
) {
282 // XXX Do we want DECODE_START_LEGACY_COMPAT_LEN(2, 1, 1, bl); ?
284 decode(bucket_name
, bl
);
285 decode(bucket_id
, bl
);
287 decode(exp_time
, bl
);
296 void dump(Formatter
*f
) const;
297 static void generate_test_instances(std::list
<objexp_hint_entry
*>& o
);
299 WRITE_CLASS_ENCODER(objexp_hint_entry
)
301 class RGWMetaSyncStatusManager
;
302 class RGWDataSyncStatusManager
;
303 class RGWCoroutinesManagerRegistry
;
305 class RGWGetDirHeader_CB
;
306 class RGWGetUserHeader_CB
;
307 namespace rgw
{ namespace sal
{
310 class MPRadosSerializer
;
311 class LCRadosSerializer
;
314 class RGWAsyncRadosProcessor
;
317 class RGWChainedCacheImpl
;
319 struct bucket_info_entry
{
322 std::map
<std::string
, bufferlist
> attrs
;
325 struct tombstone_entry
;
327 template <class K
, class V
>
329 using tombstone_cache_t
= lru_map
<rgw_obj
, tombstone_entry
>;
331 class RGWIndexCompletionManager
;
336 friend class RGWMetaNotifier
;
337 friend class RGWDataNotifier
;
338 friend class RGWObjectExpirer
;
339 friend class RGWMetaSyncProcessorThread
;
340 friend class RGWDataSyncProcessorThread
;
341 friend class RGWReshard
;
342 friend class RGWBucketReshard
;
343 friend class RGWBucketReshardLock
;
344 friend class BucketIndexLockGuard
;
345 friend class rgw::sal::MPRadosSerializer
;
346 friend class rgw::sal::LCRadosSerializer
;
347 friend class rgw::sal::RadosStore
;
349 /** Open the pool used as root for this gateway */
350 int open_root_pool_ctx(const DoutPrefixProvider
*dpp
);
351 int open_gc_pool_ctx(const DoutPrefixProvider
*dpp
);
352 int open_lc_pool_ctx(const DoutPrefixProvider
*dpp
);
353 int open_objexp_pool_ctx(const DoutPrefixProvider
*dpp
);
354 int open_reshard_pool_ctx(const DoutPrefixProvider
*dpp
);
355 int open_notif_pool_ctx(const DoutPrefixProvider
*dpp
);
357 int open_pool_ctx(const DoutPrefixProvider
*dpp
, const rgw_pool
& pool
, librados::IoCtx
& io_ctx
,
361 ceph::mutex lock
= ceph::make_mutex("rados_timer_lock");
364 rgw::sal::RadosStore
* store
= nullptr;
367 RGWObjectExpirer
*obj_expirer
;
371 bool run_sync_thread
;
372 bool run_reshard_thread
;
374 RGWMetaNotifier
*meta_notifier
;
375 RGWDataNotifier
*data_notifier
;
376 RGWMetaSyncProcessorThread
*meta_sync_processor_thread
;
377 RGWSyncTraceManager
*sync_tracer
= nullptr;
378 std::map
<rgw_zone_id
, RGWDataSyncProcessorThread
*> data_sync_processor_threads
;
380 boost::optional
<rgw::BucketTrimManager
> bucket_trim
;
381 RGWSyncLogTrimThread
*sync_log_trimmer
{nullptr};
383 ceph::mutex meta_sync_thread_lock
= ceph::make_mutex("meta_sync_thread_lock");
384 ceph::mutex data_sync_thread_lock
= ceph::make_mutex("data_sync_thread_lock");
386 librados::IoCtx root_pool_ctx
; // .rgw
388 double inject_notify_timeout_probability
= 0;
389 unsigned max_notify_retries
= 0;
391 friend class RGWWatcher
;
393 ceph::mutex bucket_id_lock
= ceph::make_mutex("rados_bucket_id");
395 // This field represents the number of bucket index object shards
396 uint32_t bucket_index_max_shards
;
398 std::string
get_cluster_fsid(const DoutPrefixProvider
*dpp
, optional_yield y
);
400 int get_obj_head_ref(const DoutPrefixProvider
*dpp
, const rgw_placement_rule
& target_placement_rule
, const rgw_obj
& obj
, rgw_rados_ref
*ref
);
401 int get_obj_head_ref(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, rgw_rados_ref
*ref
);
402 int get_system_obj_ref(const DoutPrefixProvider
*dpp
, const rgw_raw_obj
& obj
, rgw_rados_ref
*ref
);
403 uint64_t max_bucket_id
;
405 int get_olh_target_state(const DoutPrefixProvider
*dpp
, RGWObjectCtx
& rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
,
406 RGWObjState
*olh_state
, RGWObjState
**target_state
, optional_yield y
);
407 int get_obj_state_impl(const DoutPrefixProvider
*dpp
, RGWObjectCtx
*rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, RGWObjState
**state
,
408 bool follow_olh
, optional_yield y
, bool assume_noent
= false);
409 int append_atomic_test(const DoutPrefixProvider
*dpp
, RGWObjectCtx
*rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
,
410 librados::ObjectOperation
& op
, RGWObjState
**state
, optional_yield y
);
412 int update_placement_map();
413 int store_bucket_info(RGWBucketInfo
& info
, std::map
<std::string
, bufferlist
> *pattrs
, RGWObjVersionTracker
*objv_tracker
, bool exclusive
);
415 void remove_rgw_head_obj(librados::ObjectWriteOperation
& op
);
416 void cls_obj_check_prefix_exist(librados::ObjectOperation
& op
, const std::string
& prefix
, bool fail_if_exist
);
417 void cls_obj_check_mtime(librados::ObjectOperation
& op
, const real_time
& mtime
, bool high_precision_time
, RGWCheckMTimeType type
);
421 librados::Rados rados
;
423 using RGWChainedCacheImpl_bucket_info_entry
= RGWChainedCacheImpl
<bucket_info_entry
>;
424 RGWChainedCacheImpl_bucket_info_entry
*binfo_cache
;
426 tombstone_cache_t
*obj_tombstone_cache
;
428 librados::IoCtx gc_pool_ctx
; // .rgw.gc
429 librados::IoCtx lc_pool_ctx
; // .rgw.lc
430 librados::IoCtx objexp_pool_ctx
;
431 librados::IoCtx reshard_pool_ctx
;
432 librados::IoCtx notif_pool_ctx
; // .rgw.notif
434 bool pools_initialized
;
436 RGWQuotaHandler
*quota_handler
;
438 RGWCoroutinesManagerRegistry
*cr_registry
;
440 RGWSyncModuleInstanceRef sync_module
;
441 bool writeable_zone
{false};
443 RGWIndexCompletionManager
*index_completion_manager
{nullptr};
445 bool use_cache
{false};
447 bool use_datacache
{false};
449 int get_obj_head_ioctx(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, librados::IoCtx
*ioctx
);
451 RGWRados(): timer(NULL
),
452 gc(NULL
), lc(NULL
), obj_expirer(NULL
), use_gc_thread(false), use_lc_thread(false), quota_threads(false),
453 run_sync_thread(false), run_reshard_thread(false), meta_notifier(NULL
),
454 data_notifier(NULL
), meta_sync_processor_thread(NULL
),
455 bucket_index_max_shards(0),
456 max_bucket_id(0), cct(NULL
),
457 binfo_cache(NULL
), obj_tombstone_cache(nullptr),
458 pools_initialized(false),
464 RGWRados
& set_use_cache(bool status
) {
469 RGWRados
& set_use_gc(bool status
) {
474 RGWRados
& set_use_datacache(bool status
) {
475 use_datacache
= status
;
479 bool get_use_datacache() {
480 return use_datacache
;
491 RGWRados
& set_run_gc_thread(bool _use_gc_thread
) {
492 use_gc_thread
= _use_gc_thread
;
496 RGWRados
& set_run_lc_thread(bool _use_lc_thread
) {
497 use_lc_thread
= _use_lc_thread
;
501 RGWRados
& set_run_quota_threads(bool _run_quota_threads
) {
502 quota_threads
= _run_quota_threads
;
506 RGWRados
& set_run_sync_thread(bool _run_sync_thread
) {
507 run_sync_thread
= _run_sync_thread
;
511 RGWRados
& set_run_reshard_thread(bool _run_reshard_thread
) {
512 run_reshard_thread
= _run_reshard_thread
;
516 uint64_t get_new_req_id() {
517 return ceph::util::generate_random_number
<uint64_t>();
520 librados::IoCtx
* get_lc_pool_ctx() {
524 librados::IoCtx
& get_notif_pool_ctx() {
525 return notif_pool_ctx
;
528 void set_context(CephContext
*_cct
) {
531 void set_store(rgw::sal::RadosStore
* _store
) {
538 RGWCtl
*pctl
{nullptr};
541 * AmazonS3 errors contain a HostId string, but is an opaque base64 blob; we
542 * try to be more transparent. This has a wrapper so we can update it when zonegroup/zone are changed.
547 std::shared_ptr
<RGWReshardWait
> reshard_wait
;
549 virtual ~RGWRados() = default;
551 tombstone_cache_t
*get_tombstone_cache() {
552 return obj_tombstone_cache
;
554 const RGWSyncModuleInstanceRef
& get_sync_module() {
557 RGWSyncTraceManager
*get_sync_tracer() {
561 int get_required_alignment(const DoutPrefixProvider
*dpp
, const rgw_pool
& pool
, uint64_t *alignment
);
562 void get_max_aligned_size(uint64_t size
, uint64_t alignment
, uint64_t *max_size
);
563 int get_max_chunk_size(const rgw_pool
& pool
, uint64_t *max_chunk_size
, const DoutPrefixProvider
*dpp
, uint64_t *palignment
= nullptr);
564 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);
566 uint32_t get_max_bucket_shards() {
567 return RGWSI_BucketIndex_RADOS::shards_max();
571 int get_raw_obj_ref(const DoutPrefixProvider
*dpp
, const rgw_raw_obj
& obj
, rgw_rados_ref
*ref
);
573 int list_raw_objects_init(const DoutPrefixProvider
*dpp
, const rgw_pool
& pool
, const std::string
& marker
, RGWListRawObjsCtx
*ctx
);
574 int list_raw_objects_next(const DoutPrefixProvider
*dpp
, const std::string
& prefix_filter
, int max
,
575 RGWListRawObjsCtx
& ctx
, std::list
<std::string
>& oids
,
577 int list_raw_objects(const DoutPrefixProvider
*dpp
, const rgw_pool
& pool
, const std::string
& prefix_filter
, int max
,
578 RGWListRawObjsCtx
& ctx
, std::list
<std::string
>& oids
,
580 std::string
list_raw_objs_get_cursor(RGWListRawObjsCtx
& ctx
);
582 CephContext
*ctx() { return cct
; }
583 /** do all necessary setup of the storage device */
584 int initialize(CephContext
*_cct
, const DoutPrefixProvider
*dpp
) {
586 return initialize(dpp
);
588 /** Initialize the RADOS instance and prepare to do other ops */
589 int init_svc(bool raw
, const DoutPrefixProvider
*dpp
);
590 int init_ctl(const DoutPrefixProvider
*dpp
);
591 virtual int init_rados();
592 int init_complete(const DoutPrefixProvider
*dpp
);
593 int initialize(const DoutPrefixProvider
*dpp
);
596 int register_to_service_map(const DoutPrefixProvider
*dpp
, const std::string
& daemon_type
, const std::map
<std::string
, std::string
>& meta
);
597 int update_service_map(const DoutPrefixProvider
*dpp
, std::map
<std::string
, std::string
>&& status
);
600 int log_list_init(const DoutPrefixProvider
*dpp
, const std::string
& prefix
, RGWAccessHandle
*handle
);
601 int log_list_next(RGWAccessHandle handle
, std::string
*name
);
604 int log_remove(const DoutPrefixProvider
*dpp
, const std::string
& name
);
607 int log_show_init(const DoutPrefixProvider
*dpp
, const std::string
& name
, RGWAccessHandle
*handle
);
608 int log_show_next(const DoutPrefixProvider
*dpp
, RGWAccessHandle handle
, rgw_log_entry
*entry
);
610 // log bandwidth info
611 int log_usage(const DoutPrefixProvider
*dpp
, std::map
<rgw_user_bucket
, RGWUsageBatch
>& usage_info
);
612 int read_usage(const DoutPrefixProvider
*dpp
, const rgw_user
& user
, const std::string
& bucket_name
, uint64_t start_epoch
, uint64_t end_epoch
,
613 uint32_t max_entries
, bool *is_truncated
, RGWUsageIter
& read_iter
, std::map
<rgw_user_bucket
,
614 rgw_usage_log_entry
>& usage
);
615 int trim_usage(const DoutPrefixProvider
*dpp
, const rgw_user
& user
, const std::string
& bucket_name
, uint64_t start_epoch
, uint64_t end_epoch
);
616 int clear_usage(const DoutPrefixProvider
*dpp
);
618 int create_pool(const DoutPrefixProvider
*dpp
, const rgw_pool
& pool
);
620 void create_bucket_id(std::string
*bucket_id
);
622 bool get_obj_data_pool(const rgw_placement_rule
& placement_rule
, const rgw_obj
& obj
, rgw_pool
*pool
);
623 bool obj_to_raw(const rgw_placement_rule
& placement_rule
, const rgw_obj
& obj
, rgw_raw_obj
*raw_obj
);
625 int create_bucket(const RGWUserInfo
& owner
, rgw_bucket
& bucket
,
626 const std::string
& zonegroup_id
,
627 const rgw_placement_rule
& placement_rule
,
628 const std::string
& swift_ver_location
,
629 const RGWQuotaInfo
* pquota_info
,
630 std::map
<std::string
,bufferlist
>& attrs
,
631 RGWBucketInfo
& bucket_info
,
633 obj_version
*pep_objv
,
634 ceph::real_time creation_time
,
635 rgw_bucket
*master_bucket
,
636 uint32_t *master_num_shards
,
638 const DoutPrefixProvider
*dpp
,
639 bool exclusive
= true);
641 RGWCoroutinesManagerRegistry
*get_cr_registry() { return cr_registry
; }
647 RGWSI_RADOS::Obj bucket_obj
;
649 explicit BucketShard(RGWRados
*_store
) : store(_store
), shard_id(-1) {}
650 int init(const rgw_bucket
& _bucket
, const rgw_obj
& obj
, RGWBucketInfo
* out
, const DoutPrefixProvider
*dpp
);
651 int init(const rgw_bucket
& _bucket
, int sid
, const rgw::bucket_index_layout_generation
& idx_layout
, RGWBucketInfo
* out
, const DoutPrefixProvider
*dpp
);
652 int init(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
);
653 int init(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw::bucket_index_layout_generation
& idx_layout
, int sid
);
658 RGWBucketInfo bucket_info
;
666 bool versioning_disabled
;
670 const rgw_placement_rule
*pmeta_placement_rule
;
673 int get_state(const DoutPrefixProvider
*dpp
, RGWObjState
**pstate
, bool follow_olh
, optional_yield y
, bool assume_noent
= false);
674 void invalidate_state();
676 int prepare_atomic_modification(const DoutPrefixProvider
*dpp
, librados::ObjectWriteOperation
& op
, bool reset_obj
, const std::string
*ptag
,
677 const char *ifmatch
, const char *ifnomatch
, bool removal_op
, bool modify_tail
, optional_yield y
);
678 int complete_atomic_modification(const DoutPrefixProvider
*dpp
);
681 Object(RGWRados
*_store
, const RGWBucketInfo
& _bucket_info
, RGWObjectCtx
& _ctx
, const rgw_obj
& _obj
) : store(_store
), bucket_info(_bucket_info
),
682 ctx(_ctx
), obj(_obj
), bs(store
),
683 state(NULL
), versioning_disabled(false),
684 bs_initialized(false),
685 pmeta_placement_rule(nullptr) {}
687 RGWRados
*get_store() { return store
; }
688 rgw_obj
& get_obj() { return obj
; }
689 RGWObjectCtx
& get_ctx() { return ctx
; }
690 RGWBucketInfo
& get_bucket_info() { return bucket_info
; }
691 int get_manifest(const DoutPrefixProvider
*dpp
, RGWObjManifest
**pmanifest
, optional_yield y
);
693 int get_bucket_shard(BucketShard
**pbs
, const DoutPrefixProvider
*dpp
) {
694 if (!bs_initialized
) {
696 bs
.init(bucket_info
.bucket
, obj
, nullptr /* no RGWBucketInfo */, dpp
);
700 bs_initialized
= true;
706 void set_versioning_disabled(bool status
) {
707 versioning_disabled
= status
;
710 bool versioning_enabled() {
711 return (!versioning_disabled
&& bucket_info
.versioning_enabled());
714 void set_meta_placement_rule(const rgw_placement_rule
*p
) {
715 pmeta_placement_rule
= p
;
718 const rgw_placement_rule
& get_meta_placement_rule() {
719 return pmeta_placement_rule
? *pmeta_placement_rule
: bucket_info
.placement_rule
;
723 RGWRados::Object
*source
;
726 std::map
<rgw_pool
, librados::IoCtx
> io_ctxs
;
728 librados::IoCtx
*cur_ioctx
{nullptr};
730 rgw_raw_obj head_obj
;
733 struct ConditionParams
{
734 const ceph::real_time
*mod_ptr
;
735 const ceph::real_time
*unmod_ptr
;
736 bool high_precision_time
;
737 uint32_t mod_zone_id
;
739 const char *if_match
;
740 const char *if_nomatch
;
743 mod_ptr(NULL
), unmod_ptr(NULL
), high_precision_time(false), mod_zone_id(0), mod_pg_ver(0),
744 if_match(NULL
), if_nomatch(NULL
) {}
748 ceph::real_time
*lastmod
;
750 std::map
<std::string
, bufferlist
> *attrs
;
753 Params() : lastmod(nullptr), obj_size(nullptr), attrs(nullptr),
754 target_obj(nullptr) {}
757 explicit Read(RGWRados::Object
*_source
) : source(_source
) {}
759 int prepare(optional_yield y
, const DoutPrefixProvider
*dpp
);
760 static int range_to_ofs(uint64_t obj_size
, int64_t &ofs
, int64_t &end
);
761 int read(int64_t ofs
, int64_t end
, bufferlist
& bl
, optional_yield y
, const DoutPrefixProvider
*dpp
);
762 int iterate(const DoutPrefixProvider
*dpp
, int64_t ofs
, int64_t end
, RGWGetDataCB
*cb
, optional_yield y
);
763 int get_attr(const DoutPrefixProvider
*dpp
, const char *name
, bufferlist
& dest
, optional_yield y
);
767 RGWRados::Object
*target
;
770 ceph::real_time
*mtime
;
771 std::map
<std::string
, bufferlist
>* rmattrs
;
772 const bufferlist
*data
;
773 RGWObjManifest
*manifest
;
774 const std::string
*ptag
;
775 std::list
<rgw_obj_index_key
> *remove_objs
;
776 ceph::real_time set_mtime
;
778 RGWObjCategory category
;
780 const char *if_match
;
781 const char *if_nomatch
;
782 std::optional
<uint64_t> olh_epoch
;
783 ceph::real_time delete_at
;
785 const std::string
*user_data
;
786 rgw_zone_set
*zones_trace
;
788 bool completeMultipart
;
791 MetaParams() : mtime(NULL
), rmattrs(NULL
), data(NULL
), manifest(NULL
), ptag(NULL
),
792 remove_objs(NULL
), category(RGWObjCategory::Main
), flags(0),
793 if_match(NULL
), if_nomatch(NULL
), canceled(false), user_data(nullptr), zones_trace(nullptr),
794 modify_tail(false), completeMultipart(false), appendable(false) {}
797 explicit Write(RGWRados::Object
*_target
) : target(_target
) {}
799 int _do_write_meta(const DoutPrefixProvider
*dpp
,
800 uint64_t size
, uint64_t accounted_size
,
801 std::map
<std::string
, bufferlist
>& attrs
,
802 bool modify_tail
, bool assume_noent
,
803 void *index_op
, optional_yield y
);
804 int write_meta(const DoutPrefixProvider
*dpp
, uint64_t size
, uint64_t accounted_size
,
805 std::map
<std::string
, bufferlist
>& attrs
, optional_yield y
);
806 int write_data(const char *data
, uint64_t ofs
, uint64_t len
, bool exclusive
);
807 const req_state
* get_req_state() {
808 return (req_state
*)target
->get_ctx().get_private();
813 RGWRados::Object
*target
;
815 struct DeleteParams
{
816 rgw_user bucket_owner
;
817 int versioning_status
; // versioning flags defined in enum RGWBucketFlags
818 ACLOwner obj_owner
; // needed for creation of deletion marker
820 std::string marker_version_id
;
821 uint32_t bilog_flags
;
822 std::list
<rgw_obj_index_key
> *remove_objs
;
823 ceph::real_time expiration_time
;
824 ceph::real_time unmod_since
;
825 ceph::real_time mtime
; /* for setting delete marker mtime */
826 bool high_precision_time
;
827 rgw_zone_set
*zones_trace
;
829 uint64_t parts_accounted_size
;
831 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) {}
834 struct DeleteResult
{
836 std::string version_id
;
838 DeleteResult() : delete_marker(false) {}
841 explicit Delete(RGWRados::Object
*_target
) : target(_target
) {}
843 int delete_obj(optional_yield y
, const DoutPrefixProvider
*dpp
);
847 RGWRados::Object
*source
;
851 std::optional
<RGWObjManifest
> manifest
;
853 struct timespec mtime
{};
854 std::map
<std::string
, bufferlist
> attrs
;
858 librados::IoCtx io_ctx
;
859 librados::AioCompletion
*completion
;
862 State() : completion(NULL
), ret(0) {}
866 explicit Stat(RGWRados::Object
*_source
) : source(_source
) {}
868 int stat_async(const DoutPrefixProvider
*dpp
);
869 int wait(const DoutPrefixProvider
*dpp
);
872 int finish(const DoutPrefixProvider
*dpp
);
878 RGWBucketInfo bucket_info
;
883 Bucket(RGWRados
*_store
, const RGWBucketInfo
& _bucket_info
) : store(_store
), bucket_info(_bucket_info
), bucket(bucket_info
.bucket
),
884 shard_id(RGW_NO_SHARD
) {}
885 RGWRados
*get_store() { return store
; }
886 rgw_bucket
& get_bucket() { return bucket
; }
887 RGWBucketInfo
& get_bucket_info() { return bucket_info
; }
889 int update_bucket_id(const std::string
& new_bucket_id
, const DoutPrefixProvider
*dpp
);
891 int get_shard_id() { return shard_id
; }
892 void set_shard_id(int id
) {
897 RGWRados::Bucket
*target
;
900 uint16_t bilog_flags
{0};
902 bool bs_initialized
{false};
904 bool prepared
{false};
905 rgw_zone_set
*zones_trace
{nullptr};
907 int init_bs(const DoutPrefixProvider
*dpp
) {
909 bs
.init(target
->get_bucket(), obj
, nullptr /* no RGWBucketInfo */, dpp
);
913 bs_initialized
= true;
917 void invalidate_bs() {
918 bs_initialized
= false;
921 int guard_reshard(const DoutPrefixProvider
*dpp
, BucketShard
**pbs
, std::function
<int(BucketShard
*)> call
);
924 UpdateIndex(RGWRados::Bucket
*_target
, const rgw_obj
& _obj
) : target(_target
), obj(_obj
),
925 bs(target
->get_store()) {
926 blind
= (target
->get_bucket_info().layout
.current_index
.layout
.type
== rgw::BucketIndexType::Indexless
);
929 int get_bucket_shard(BucketShard
**pbs
, const DoutPrefixProvider
*dpp
) {
930 if (!bs_initialized
) {
931 int r
= init_bs(dpp
);
940 void set_bilog_flags(uint16_t flags
) {
944 void set_zones_trace(rgw_zone_set
*_zones_trace
) {
945 zones_trace
= _zones_trace
;
948 int prepare(const DoutPrefixProvider
*dpp
, RGWModifyOp
, const std::string
*write_tag
, optional_yield y
);
949 int complete(const DoutPrefixProvider
*dpp
, int64_t poolid
, uint64_t epoch
, uint64_t size
,
950 uint64_t accounted_size
, ceph::real_time
& ut
,
951 const std::string
& etag
, const std::string
& content_type
,
952 const std::string
& storage_class
,
953 bufferlist
*acl_bl
, RGWObjCategory category
,
954 std::list
<rgw_obj_index_key
> *remove_objs
, const std::string
*user_data
= nullptr, bool appendable
= false);
955 int complete_del(const DoutPrefixProvider
*dpp
,
956 int64_t poolid
, uint64_t epoch
,
957 ceph::real_time
& removed_mtime
, /* mtime of removed object */
958 std::list
<rgw_obj_index_key
> *remove_objs
);
959 int cancel(const DoutPrefixProvider
*dpp
,
960 std::list
<rgw_obj_index_key
> *remove_objs
);
962 const std::string
*get_optag() { return &optag
; }
964 bool is_prepared() { return prepared
; }
965 }; // class UpdateIndex
969 // absolute maximum number of objects that
970 // list_objects_(un)ordered can return
971 static constexpr int64_t bucket_list_objects_absolute_max
= 25000;
973 RGWRados::Bucket
*target
;
974 rgw_obj_key next_marker
;
976 int list_objects_ordered(const DoutPrefixProvider
*dpp
,
978 std::vector
<rgw_bucket_dir_entry
> *result
,
979 std::map
<std::string
, bool> *common_prefixes
,
982 int list_objects_unordered(const DoutPrefixProvider
*dpp
,
984 std::vector
<rgw_bucket_dir_entry
> *result
,
985 std::map
<std::string
, bool> *common_prefixes
,
995 rgw_obj_key end_marker
;
998 RGWAccessListFilter
* access_list_filter
;
999 RGWBucketListNameFilter force_check_filter
;
1001 bool allow_unordered
;
1005 access_list_filter(nullptr),
1006 list_versions(false),
1007 allow_unordered(false)
1011 explicit List(RGWRados::Bucket
*_target
) : target(_target
) {}
1013 int list_objects(const DoutPrefixProvider
*dpp
, int64_t max
,
1014 std::vector
<rgw_bucket_dir_entry
> *result
,
1015 std::map
<std::string
, bool> *common_prefixes
,
1018 if (params
.allow_unordered
) {
1019 return list_objects_unordered(dpp
, max
, result
, common_prefixes
,
1022 return list_objects_ordered(dpp
, max
, result
, common_prefixes
,
1026 rgw_obj_key
& get_next_marker() {
1032 int on_last_entry_in_listing(const DoutPrefixProvider
*dpp
,
1033 RGWBucketInfo
& bucket_info
,
1034 const std::string
& obj_prefix
,
1035 const std::string
& obj_delim
,
1036 std::function
<int(const rgw_bucket_dir_entry
&)> handler
);
1038 bool swift_versioning_enabled(rgw::sal::Bucket
* bucket
) const;
1040 int swift_versioning_copy(RGWObjectCtx
& obj_ctx
, /* in/out */
1041 const rgw_user
& user
, /* in */
1042 rgw::sal::Bucket
* bucket
, /* in */
1043 rgw::sal::Object
* obj
, /* in */
1044 const DoutPrefixProvider
*dpp
, /* in/out */
1045 optional_yield y
); /* in */
1046 int swift_versioning_restore(RGWObjectCtx
& obj_ctx
, /* in/out */
1047 const rgw_user
& user
, /* in */
1048 rgw::sal::Bucket
* bucket
, /* in */
1049 rgw::sal::Object
* obj
, /* in */
1050 bool& restored
, /* out */
1051 const DoutPrefixProvider
*dpp
); /* in/out */
1052 int copy_obj_to_remote_dest(const DoutPrefixProvider
*dpp
,
1053 RGWObjState
*astate
,
1054 std::map
<std::string
, bufferlist
>& src_attrs
,
1055 RGWRados::Object::Read
& read_op
,
1056 const rgw_user
& user_id
,
1057 rgw::sal::Object
* dest_obj
,
1058 ceph::real_time
*mtime
);
1062 ATTRSMOD_REPLACE
= 1,
1066 D3nDataCache
* d3n_data_cache
{nullptr};
1068 int rewrite_obj(rgw::sal::Object
* obj
, const DoutPrefixProvider
*dpp
, optional_yield y
);
1070 int stat_remote_obj(const DoutPrefixProvider
*dpp
,
1071 RGWObjectCtx
& obj_ctx
,
1072 const rgw_user
& user_id
,
1074 const rgw_zone_id
& source_zone
,
1075 rgw::sal::Object
* src_obj
,
1076 const RGWBucketInfo
*src_bucket_info
,
1077 real_time
*src_mtime
,
1079 const real_time
*mod_ptr
,
1080 const real_time
*unmod_ptr
,
1081 bool high_precision_time
,
1082 const char *if_match
,
1083 const char *if_nomatch
,
1084 std::map
<std::string
, bufferlist
> *pattrs
,
1085 std::map
<std::string
, std::string
> *pheaders
,
1086 std::string
*version_id
,
1088 std::string
*petag
);
1090 int fetch_remote_obj(RGWObjectCtx
& obj_ctx
,
1091 const rgw_user
& user_id
,
1093 const rgw_zone_id
& source_zone
,
1094 rgw::sal::Object
* dest_obj
,
1095 rgw::sal::Object
* src_obj
,
1096 rgw::sal::Bucket
* dest_bucket
,
1097 rgw::sal::Bucket
* src_bucket
,
1098 std::optional
<rgw_placement_rule
> dest_placement
,
1099 ceph::real_time
*src_mtime
,
1100 ceph::real_time
*mtime
,
1101 const ceph::real_time
*mod_ptr
,
1102 const ceph::real_time
*unmod_ptr
,
1103 bool high_precision_time
,
1104 const char *if_match
,
1105 const char *if_nomatch
,
1108 rgw::sal::Attrs
& attrs
,
1109 RGWObjCategory category
,
1110 std::optional
<uint64_t> olh_epoch
,
1111 ceph::real_time delete_at
,
1114 void (*progress_cb
)(off_t
, void *),
1115 void *progress_data
,
1116 const DoutPrefixProvider
*dpp
,
1117 RGWFetchObjFilter
*filter
,
1118 rgw_zone_set
*zones_trace
= nullptr,
1119 std::optional
<uint64_t>* bytes_transferred
= 0);
1122 * dest_obj: the object to copy into
1123 * src_obj: the object to copy from
1124 * attrs: usage depends on attrs_mod parameter
1125 * attrs_mod: the modification mode of the attrs, may have the following values:
1126 * ATTRSMOD_NONE - the attributes of the source object will be
1127 * copied without modifications, attrs parameter is ignored;
1128 * ATTRSMOD_REPLACE - new object will have the attributes provided by attrs
1129 * parameter, source object attributes are not copied;
1130 * ATTRSMOD_MERGE - any conflicting meta keys on the source object's attributes
1131 * are overwritten by values contained in attrs parameter.
1132 * Returns: 0 on success, -ERR# otherwise.
1134 int copy_obj(RGWObjectCtx
& obj_ctx
,
1135 const rgw_user
& user_id
,
1137 const rgw_zone_id
& source_zone
,
1138 rgw::sal::Object
* dest_obj
,
1139 rgw::sal::Object
* src_obj
,
1140 rgw::sal::Bucket
* dest_bucket
,
1141 rgw::sal::Bucket
* src_bucket
,
1142 const rgw_placement_rule
& dest_placement
,
1143 ceph::real_time
*src_mtime
,
1144 ceph::real_time
*mtime
,
1145 const ceph::real_time
*mod_ptr
,
1146 const ceph::real_time
*unmod_ptr
,
1147 bool high_precision_time
,
1148 const char *if_match
,
1149 const char *if_nomatch
,
1152 std::map
<std::string
, bufferlist
>& attrs
,
1153 RGWObjCategory category
,
1155 ceph::real_time delete_at
,
1156 std::string
*version_id
,
1159 void (*progress_cb
)(off_t
, void *),
1160 void *progress_data
,
1161 const DoutPrefixProvider
*dpp
,
1164 int copy_obj_data(RGWObjectCtx
& obj_ctx
,
1165 rgw::sal::Bucket
* bucket
,
1166 const rgw_placement_rule
& dest_placement
,
1167 RGWRados::Object::Read
& read_op
, off_t end
,
1168 rgw::sal::Object
* dest_obj
,
1169 ceph::real_time
*mtime
,
1170 ceph::real_time set_mtime
,
1171 std::map
<std::string
, bufferlist
>& attrs
,
1173 ceph::real_time delete_at
,
1175 const DoutPrefixProvider
*dpp
,
1178 int transition_obj(RGWObjectCtx
& obj_ctx
,
1179 rgw::sal::Bucket
* bucket
,
1180 rgw::sal::Object
& obj
,
1181 const rgw_placement_rule
& placement_rule
,
1182 const real_time
& mtime
,
1184 const DoutPrefixProvider
*dpp
,
1187 int check_bucket_empty(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
, optional_yield y
);
1191 * bucket: the name of the bucket to delete
1192 * Returns 0 on success, -ERR# otherwise.
1194 int delete_bucket(RGWBucketInfo
& bucket_info
, RGWObjVersionTracker
& objv_tracker
, optional_yield y
, const DoutPrefixProvider
*dpp
, bool check_empty
= true);
1196 void wakeup_meta_sync_shards(std::set
<int>& shard_ids
);
1197 void wakeup_data_sync_shards(const DoutPrefixProvider
*dpp
,
1198 const rgw_zone_id
& source_zone
,
1199 std::map
<int, std::set
<std::string
> >& shard_ids
);
1201 RGWMetaSyncStatusManager
* get_meta_sync_manager();
1202 RGWDataSyncStatusManager
* get_data_sync_manager(const rgw_zone_id
& source_zone
);
1204 int set_bucket_owner(rgw_bucket
& bucket
, ACLOwner
& owner
, const DoutPrefixProvider
*dpp
);
1205 int set_buckets_enabled(std::vector
<rgw_bucket
>& buckets
, bool enabled
, const DoutPrefixProvider
*dpp
);
1206 int bucket_suspended(const DoutPrefixProvider
*dpp
, rgw_bucket
& bucket
, bool *suspended
);
1208 /** Delete an object.*/
1209 int delete_obj(const DoutPrefixProvider
*dpp
,
1210 RGWObjectCtx
& obj_ctx
,
1211 const RGWBucketInfo
& bucket_owner
,
1212 const rgw_obj
& src_obj
,
1213 int versioning_status
, // versioning flags defined in enum RGWBucketFlags
1214 uint16_t bilog_flags
= 0,
1215 const ceph::real_time
& expiration_time
= ceph::real_time(),
1216 rgw_zone_set
*zones_trace
= nullptr);
1218 int delete_raw_obj(const DoutPrefixProvider
*dpp
, const rgw_raw_obj
& obj
);
1220 /** Remove an object from the bucket index */
1221 int delete_obj_index(const rgw_obj
& obj
, ceph::real_time mtime
, const DoutPrefixProvider
*dpp
);
1224 * Set an attr on an object.
1225 * bucket: name of the bucket holding the object
1226 * obj: name of the object to set the attr on
1227 * name: the attr to set
1228 * bl: the contents of the attr
1229 * Returns: 0 on success, -ERR# otherwise.
1231 int set_attr(const DoutPrefixProvider
*dpp
, void *ctx
, const RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, const char *name
, bufferlist
& bl
);
1233 int set_attrs(const DoutPrefixProvider
*dpp
, void *ctx
, const RGWBucketInfo
& bucket_info
, rgw_obj
& obj
,
1234 std::map
<std::string
, bufferlist
>& attrs
,
1235 std::map
<std::string
, bufferlist
>* rmattrs
,
1238 int get_obj_state(const DoutPrefixProvider
*dpp
, RGWObjectCtx
*rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, RGWObjState
**state
,
1239 bool follow_olh
, optional_yield y
, bool assume_noent
= false);
1240 int get_obj_state(const DoutPrefixProvider
*dpp
, RGWObjectCtx
*rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, RGWObjState
**state
, optional_yield y
) {
1241 return get_obj_state(dpp
, rctx
, bucket_info
, obj
, state
, true, y
);
1244 using iterate_obj_cb
= int (*)(const DoutPrefixProvider
*, const rgw_raw_obj
&, off_t
, off_t
,
1245 off_t
, bool, RGWObjState
*, void*);
1247 int iterate_obj(const DoutPrefixProvider
*dpp
, RGWObjectCtx
& ctx
, const RGWBucketInfo
& bucket_info
,
1248 const rgw_obj
& obj
, off_t ofs
, off_t end
,
1249 uint64_t max_chunk_size
, iterate_obj_cb cb
, void *arg
,
1252 int append_atomic_test(const DoutPrefixProvider
*dpp
, const RGWObjState
* astate
, librados::ObjectOperation
& op
);
1254 virtual int get_obj_iterate_cb(const DoutPrefixProvider
*dpp
,
1255 const rgw_raw_obj
& read_obj
, off_t obj_ofs
,
1256 off_t read_ofs
, off_t len
, bool is_head_obj
,
1257 RGWObjState
*astate
, void *arg
);
1260 * a simple object read without keeping state
1263 int raw_obj_stat(const DoutPrefixProvider
*dpp
,
1264 rgw_raw_obj
& obj
, uint64_t *psize
, ceph::real_time
*pmtime
, uint64_t *epoch
,
1265 std::map
<std::string
, bufferlist
> *attrs
, bufferlist
*first_chunk
,
1266 RGWObjVersionTracker
*objv_tracker
, optional_yield y
);
1268 int obj_operate(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, librados::ObjectWriteOperation
*op
);
1269 int obj_operate(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, librados::ObjectReadOperation
*op
);
1271 int guard_reshard(const DoutPrefixProvider
*dpp
,
1273 const rgw_obj
& obj_instance
,
1274 const RGWBucketInfo
& bucket_info
,
1275 std::function
<int(BucketShard
*)> call
);
1276 int block_while_resharding(RGWRados::BucketShard
*bs
,
1277 std::string
*new_bucket_id
,
1278 const RGWBucketInfo
& bucket_info
,
1280 const DoutPrefixProvider
*dpp
);
1282 void bucket_index_guard_olh_op(const DoutPrefixProvider
*dpp
, RGWObjState
& olh_state
, librados::ObjectOperation
& op
);
1283 int olh_init_modification(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& olh_obj
, std::string
*op_tag
);
1284 int olh_init_modification_impl(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& olh_obj
, std::string
*op_tag
);
1285 int bucket_index_link_olh(const DoutPrefixProvider
*dpp
,
1286 const RGWBucketInfo
& bucket_info
, RGWObjState
& olh_state
,
1287 const rgw_obj
& obj_instance
, bool delete_marker
,
1288 const std::string
& op_tag
, struct rgw_bucket_dir_entry_meta
*meta
,
1290 ceph::real_time unmod_since
, bool high_precision_time
,
1291 rgw_zone_set
*zones_trace
= nullptr,
1292 bool log_data_change
= false);
1293 int bucket_index_unlink_instance(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj_instance
, const std::string
& op_tag
, const std::string
& olh_tag
, uint64_t olh_epoch
, rgw_zone_set
*zones_trace
= nullptr);
1294 int bucket_index_read_olh_log(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& obj_instance
, uint64_t ver_marker
,
1295 std::map
<uint64_t, std::vector
<rgw_bucket_olh_log_entry
> > *log
, bool *is_truncated
);
1296 int bucket_index_trim_olh_log(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, RGWObjState
& obj_state
, const rgw_obj
& obj_instance
, uint64_t ver
);
1297 int bucket_index_clear_olh(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& obj_instance
);
1298 int apply_olh_log(const DoutPrefixProvider
*dpp
, RGWObjectCtx
& ctx
, RGWObjState
& obj_state
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
,
1299 bufferlist
& obj_tag
, std::map
<uint64_t, std::vector
<rgw_bucket_olh_log_entry
> >& log
,
1300 uint64_t *plast_ver
, rgw_zone_set
*zones_trace
= nullptr);
1301 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);
1302 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
,
1303 uint64_t olh_epoch
, ceph::real_time unmod_since
, bool high_precision_time
,
1304 optional_yield y
, rgw_zone_set
*zones_trace
= nullptr, bool log_data_change
= false);
1305 int repair_olh(const DoutPrefixProvider
*dpp
, RGWObjState
* state
, const RGWBucketInfo
& bucket_info
,
1306 const rgw_obj
& obj
);
1307 int unlink_obj_instance(const DoutPrefixProvider
*dpp
, RGWObjectCtx
& obj_ctx
, RGWBucketInfo
& bucket_info
, const rgw_obj
& target_obj
,
1308 uint64_t olh_epoch
, optional_yield y
, rgw_zone_set
*zones_trace
= nullptr);
1310 void check_pending_olh_entries(const DoutPrefixProvider
*dpp
, std::map
<std::string
, bufferlist
>& pending_entries
, std::map
<std::string
, bufferlist
> *rm_pending_entries
);
1311 int remove_olh_pending_entries(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& olh_obj
, std::map
<std::string
, bufferlist
>& pending_attrs
);
1312 int follow_olh(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, RGWObjectCtx
& ctx
, RGWObjState
*state
, const rgw_obj
& olh_obj
, rgw_obj
*target
);
1313 int get_olh(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, RGWOLHInfo
*olh
);
1315 void gen_rand_obj_instance_name(rgw_obj_key
*target_key
);
1316 void gen_rand_obj_instance_name(rgw_obj
*target
);
1318 int update_containers_stats(std::map
<std::string
, RGWBucketEnt
>& m
, const DoutPrefixProvider
*dpp
);
1319 int append_async(const DoutPrefixProvider
*dpp
, rgw_raw_obj
& obj
, size_t size
, bufferlist
& bl
);
1322 void set_atomic(void *ctx
, rgw_obj
& obj
) {
1323 RGWObjectCtx
*rctx
= static_cast<RGWObjectCtx
*>(ctx
);
1324 rctx
->set_atomic(obj
);
1326 void set_prefetch_data(void *ctx
, const rgw_obj
& obj
) {
1327 RGWObjectCtx
*rctx
= static_cast<RGWObjectCtx
*>(ctx
);
1328 rctx
->set_prefetch_data(obj
);
1330 void set_compressed(void *ctx
, const rgw_obj
& obj
) {
1331 RGWObjectCtx
*rctx
= static_cast<RGWObjectCtx
*>(ctx
);
1332 rctx
->set_compressed(obj
);
1334 int decode_policy(const DoutPrefixProvider
*dpp
, bufferlist
& bl
, ACLOwner
*owner
);
1335 int get_bucket_stats(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
, int shard_id
, std::string
*bucket_ver
, std::string
*master_ver
,
1336 std::map
<RGWObjCategory
, RGWStorageStats
>& stats
, std::string
*max_marker
, bool* syncstopped
= NULL
);
1337 int get_bucket_stats_async(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
, int shard_id
, RGWGetBucketStats_CB
*cb
);
1339 int put_bucket_instance_info(RGWBucketInfo
& info
, bool exclusive
, ceph::real_time mtime
, std::map
<std::string
, bufferlist
> *pattrs
, const DoutPrefixProvider
*dpp
);
1340 /* xxx dang obj_ctx -> svc */
1341 int get_bucket_instance_info(RGWSysObjectCtx
& obj_ctx
, const std::string
& meta_key
, RGWBucketInfo
& info
, ceph::real_time
*pmtime
, std::map
<std::string
, bufferlist
> *pattrs
, optional_yield y
, const DoutPrefixProvider
*dpp
);
1342 int get_bucket_instance_info(RGWSysObjectCtx
& obj_ctx
, const rgw_bucket
& bucket
, RGWBucketInfo
& info
, ceph::real_time
*pmtime
, std::map
<std::string
, bufferlist
> *pattrs
, optional_yield y
, const DoutPrefixProvider
*dpp
);
1344 static void make_bucket_entry_name(const std::string
& tenant_name
, const std::string
& bucket_name
, std::string
& bucket_entry
);
1346 int get_bucket_info(RGWServices
*svc
,
1347 const std::string
& tenant_name
, const std::string
& bucket_name
,
1348 RGWBucketInfo
& info
,
1349 ceph::real_time
*pmtime
, optional_yield y
,
1350 const DoutPrefixProvider
*dpp
, std::map
<std::string
, bufferlist
> *pattrs
= NULL
);
1352 // Returns 0 on successful refresh. Returns error code if there was
1353 // an error or the version stored on the OSD is the same as that
1354 // presented in the BucketInfo structure.
1356 int try_refresh_bucket_info(RGWBucketInfo
& info
,
1357 ceph::real_time
*pmtime
,
1358 const DoutPrefixProvider
*dpp
,
1359 std::map
<std::string
, bufferlist
> *pattrs
= nullptr);
1361 int put_linked_bucket_info(RGWBucketInfo
& info
, bool exclusive
, ceph::real_time mtime
, obj_version
*pep_objv
,
1362 std::map
<std::string
, bufferlist
> *pattrs
, bool create_entry_point
,
1363 const DoutPrefixProvider
*dpp
);
1365 int cls_obj_prepare_op(const DoutPrefixProvider
*dpp
, BucketShard
& bs
, RGWModifyOp op
, std::string
& tag
, rgw_obj
& obj
, uint16_t bilog_flags
, optional_yield y
, rgw_zone_set
*zones_trace
= nullptr);
1366 int cls_obj_complete_op(BucketShard
& bs
, const rgw_obj
& obj
, RGWModifyOp op
, std::string
& tag
, int64_t pool
, uint64_t epoch
,
1367 rgw_bucket_dir_entry
& ent
, RGWObjCategory category
, std::list
<rgw_obj_index_key
> *remove_objs
, uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
1368 int cls_obj_complete_add(BucketShard
& bs
, const rgw_obj
& obj
, std::string
& tag
, int64_t pool
, uint64_t epoch
, rgw_bucket_dir_entry
& ent
,
1369 RGWObjCategory category
, std::list
<rgw_obj_index_key
> *remove_objs
, uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
1370 int cls_obj_complete_del(BucketShard
& bs
, std::string
& tag
, int64_t pool
, uint64_t epoch
, rgw_obj
& obj
,
1371 ceph::real_time
& removed_mtime
, std::list
<rgw_obj_index_key
> *remove_objs
, uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
1372 int cls_obj_complete_cancel(BucketShard
& bs
, std::string
& tag
, rgw_obj
& obj
,
1373 std::list
<rgw_obj_index_key
> *remove_objs
,
1374 uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
1375 int cls_obj_set_bucket_tag_timeout(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
, uint64_t timeout
);
1378 boost::container::flat_map
<std::string
, rgw_bucket_dir_entry
>;
1380 int cls_bucket_list_ordered(const DoutPrefixProvider
*dpp
,
1381 RGWBucketInfo
& bucket_info
,
1383 const rgw_obj_index_key
& start_after
,
1384 const std::string
& prefix
,
1385 const std::string
& delimiter
,
1386 const uint32_t num_entries
,
1387 const bool list_versions
,
1388 const uint16_t exp_factor
, // 0 means ignore
1392 rgw_obj_index_key
*last_entry
,
1394 RGWBucketListNameFilter force_check_filter
= {});
1395 int cls_bucket_list_unordered(const DoutPrefixProvider
*dpp
,
1396 RGWBucketInfo
& bucket_info
,
1398 const rgw_obj_index_key
& start_after
,
1399 const std::string
& prefix
,
1400 uint32_t num_entries
,
1402 std::vector
<rgw_bucket_dir_entry
>& ent_list
,
1404 rgw_obj_index_key
*last_entry
,
1406 RGWBucketListNameFilter force_check_filter
= {});
1407 int cls_bucket_head(const DoutPrefixProvider
*dpp
,
1408 const RGWBucketInfo
& bucket_info
,
1410 std::vector
<rgw_bucket_dir_header
>& headers
,
1411 std::map
<int, std::string
> *bucket_instance_ids
= NULL
);
1412 int cls_bucket_head_async(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, int shard_id
, RGWGetDirHeader_CB
*ctx
, int *num_aio
);
1414 int bi_get_instance(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, rgw_bucket_dir_entry
*dirent
);
1415 int bi_get_olh(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, rgw_bucket_olh_entry
*olh
);
1416 int bi_get(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, BIIndexType index_type
, rgw_cls_bi_entry
*entry
);
1417 void bi_put(librados::ObjectWriteOperation
& op
, BucketShard
& bs
, rgw_cls_bi_entry
& entry
);
1418 int bi_put(BucketShard
& bs
, rgw_cls_bi_entry
& entry
);
1419 int bi_put(const DoutPrefixProvider
*dpp
, rgw_bucket
& bucket
, rgw_obj
& obj
, rgw_cls_bi_entry
& entry
);
1420 int bi_list(const DoutPrefixProvider
*dpp
,
1421 const RGWBucketInfo
& bucket_info
,
1423 const std::string
& filter_obj
,
1424 const std::string
& marker
,
1426 std::list
<rgw_cls_bi_entry
> *entries
,
1427 bool *is_truncated
);
1428 int bi_list(BucketShard
& bs
, const std::string
& filter_obj
, const std::string
& marker
, uint32_t max
, std::list
<rgw_cls_bi_entry
> *entries
, bool *is_truncated
);
1429 int bi_list(const DoutPrefixProvider
*dpp
, rgw_bucket
& bucket
, const std::string
& obj_name
, const std::string
& marker
, uint32_t max
,
1430 std::list
<rgw_cls_bi_entry
> *entries
, bool *is_truncated
);
1431 int bi_remove(const DoutPrefixProvider
*dpp
, BucketShard
& bs
);
1433 int cls_obj_usage_log_add(const DoutPrefixProvider
*dpp
, const std::string
& oid
, rgw_usage_log_info
& info
);
1434 int cls_obj_usage_log_read(const DoutPrefixProvider
*dpp
, const std::string
& oid
, const std::string
& user
, const std::string
& bucket
, uint64_t start_epoch
,
1435 uint64_t end_epoch
, uint32_t max_entries
, std::string
& read_iter
,
1436 std::map
<rgw_user_bucket
, rgw_usage_log_entry
>& usage
, bool *is_truncated
);
1437 int cls_obj_usage_log_trim(const DoutPrefixProvider
*dpp
, const std::string
& oid
, const std::string
& user
, const std::string
& bucket
, uint64_t start_epoch
,
1438 uint64_t end_epoch
);
1439 int cls_obj_usage_log_clear(const DoutPrefixProvider
*dpp
, std::string
& oid
);
1441 int get_target_shard_id(const rgw::bucket_index_normal_layout
& layout
, const std::string
& obj_key
, int *shard_id
);
1443 int lock_exclusive(const rgw_pool
& pool
, const std::string
& oid
, ceph::timespan
& duration
, rgw_zone_id
& zone_id
, std::string
& owner_id
);
1444 int unlock(const rgw_pool
& pool
, const std::string
& oid
, rgw_zone_id
& zone_id
, std::string
& owner_id
);
1446 void update_gc_chain(const DoutPrefixProvider
*dpp
, rgw_obj
& head_obj
, RGWObjManifest
& manifest
, cls_rgw_obj_chain
*chain
);
1447 int send_chain_to_gc(cls_rgw_obj_chain
& chain
, const std::string
& tag
);
1448 void delete_objs_inline(const DoutPrefixProvider
*dpp
, cls_rgw_obj_chain
& chain
, const std::string
& tag
);
1449 int gc_operate(const DoutPrefixProvider
*dpp
, std::string
& oid
, librados::ObjectWriteOperation
*op
);
1450 int gc_aio_operate(const std::string
& oid
, librados::AioCompletion
*c
,
1451 librados::ObjectWriteOperation
*op
);
1452 int gc_operate(const DoutPrefixProvider
*dpp
, std::string
& oid
, librados::ObjectReadOperation
*op
, bufferlist
*pbl
);
1454 int list_gc_objs(int *index
, std::string
& marker
, uint32_t max
, bool expired_only
, std::list
<cls_rgw_gc_obj_info
>& result
, bool *truncated
, bool& processing_queue
);
1455 int process_gc(bool expired_only
);
1456 bool process_expire_objects(const DoutPrefixProvider
*dpp
);
1457 int defer_gc(const DoutPrefixProvider
*dpp
, void *ctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, optional_yield y
);
1459 int process_lc(const std::unique_ptr
<rgw::sal::Bucket
>& optional_bucket
);
1460 int list_lc_progress(std::string
& marker
, uint32_t max_entries
,
1461 std::vector
<rgw::sal::Lifecycle::LCEntry
>& progress_map
, int& index
);
1463 int bucket_check_index(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
,
1464 std::map
<RGWObjCategory
, RGWStorageStats
> *existing_stats
,
1465 std::map
<RGWObjCategory
, RGWStorageStats
> *calculated_stats
);
1466 int bucket_rebuild_index(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
);
1467 int bucket_set_reshard(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, const cls_rgw_bucket_instance_entry
& entry
);
1468 int remove_objs_from_index(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
, std::list
<rgw_obj_index_key
>& oid_list
);
1469 int move_rados_obj(const DoutPrefixProvider
*dpp
,
1470 librados::IoCtx
& src_ioctx
,
1471 const std::string
& src_oid
, const std::string
& src_locator
,
1472 librados::IoCtx
& dst_ioctx
,
1473 const std::string
& dst_oid
, const std::string
& dst_locator
);
1474 int fix_head_obj_locator(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, bool copy_obj
, bool remove_bad
, rgw_obj_key
& key
);
1475 int fix_tail_obj_locator(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, rgw_obj_key
& key
, bool fix
, bool *need_fix
, optional_yield y
);
1477 int check_quota(const DoutPrefixProvider
*dpp
, const rgw_user
& bucket_owner
, rgw_bucket
& bucket
,
1478 RGWQuotaInfo
& user_quota
, RGWQuotaInfo
& bucket_quota
, uint64_t obj_size
,
1479 optional_yield y
, bool check_size_only
= false);
1481 int check_bucket_shards(const RGWBucketInfo
& bucket_info
, const rgw_bucket
& bucket
,
1482 uint64_t num_objs
, const DoutPrefixProvider
*dpp
);
1484 int add_bucket_to_reshard(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
, uint32_t new_num_shards
);
1486 uint64_t instance_id();
1488 librados::Rados
* get_rados_handle();
1490 int delete_raw_obj_aio(const DoutPrefixProvider
*dpp
, const rgw_raw_obj
& obj
, std::list
<librados::AioCompletion
*>& handles
);
1491 int delete_obj_aio(const DoutPrefixProvider
*dpp
, const rgw_obj
& obj
, RGWBucketInfo
& info
, RGWObjState
*astate
,
1492 std::list
<librados::AioCompletion
*>& handles
, bool keep_index_consistent
,
1497 * Check the actual on-disk state of the object specified
1498 * by list_state, and fill in the time and size of object.
1499 * Then append any changes to suggested_updates for
1500 * the rgw class' dir_suggest_changes function.
1502 * Note that this can maul list_state; don't use it afterwards. Also
1503 * it expects object to already be filled in from list_state; it only
1504 * sets the size and mtime.
1506 * Returns 0 on success, -ENOENT if the object doesn't exist on disk,
1507 * and -errno on other failures. (-ENOENT is not a failure, and it
1508 * will encode that info as a suggested update.)
1510 int check_disk_state(const DoutPrefixProvider
*dpp
,
1511 librados::IoCtx io_ctx
,
1512 const RGWBucketInfo
& bucket_info
,
1513 rgw_bucket_dir_entry
& list_state
,
1514 rgw_bucket_dir_entry
& object
,
1515 bufferlist
& suggested_updates
,
1519 * Init pool iteration
1520 * pool: pool to use for the ctx initialization
1521 * ctx: context object to use for the iteration
1522 * Returns: 0 on success, -ERR# otherwise.
1524 int pool_iterate_begin(const DoutPrefixProvider
*dpp
, const rgw_pool
& pool
, RGWPoolIterCtx
& ctx
);
1527 * Init pool iteration
1529 * cursor: position to start iteration
1530 * ctx: context object to use for the iteration
1531 * Returns: 0 on success, -ERR# otherwise.
1533 int pool_iterate_begin(const DoutPrefixProvider
*dpp
, const rgw_pool
& pool
, const std::string
& cursor
, RGWPoolIterCtx
& ctx
);
1536 * Get pool iteration position
1537 * ctx: context object to use for the iteration
1538 * Returns: std::string representation of position
1540 std::string
pool_iterate_get_cursor(RGWPoolIterCtx
& ctx
);
1543 * Iterate over pool return object names, use optional filter
1544 * ctx: iteration context, initialized with pool_iterate_begin()
1545 * num: max number of objects to return
1546 * objs: a vector that the results will append into
1547 * is_truncated: if not NULL, will hold true iff iteration is complete
1548 * filter: if not NULL, will be used to filter returned objects
1549 * Returns: 0 on success, -ERR# otherwise.
1551 int pool_iterate(const DoutPrefixProvider
*dpp
, RGWPoolIterCtx
& ctx
, uint32_t num
,
1552 std::vector
<rgw_bucket_dir_entry
>& objs
,
1553 bool *is_truncated
, RGWAccessListFilter
*filter
);
1555 uint64_t next_bucket_id();
1558 * This is broken out to facilitate unit testing.
1560 static uint32_t calc_ordered_bucket_list_per_shard(uint32_t num_entries
,
1561 uint32_t num_shards
);
1565 struct get_obj_data
{
1567 RGWGetDataCB
* client_cb
= nullptr;
1569 uint64_t offset
; // next offset to write to client
1570 rgw::AioResultList completed
; // completed read results, sorted by offset
1571 optional_yield yield
;
1573 get_obj_data(RGWRados
* rgwrados
, RGWGetDataCB
* cb
, rgw::Aio
* aio
,
1574 uint64_t offset
, optional_yield yield
)
1575 : rgwrados(rgwrados
), client_cb(cb
), aio(aio
), offset(offset
), yield(yield
) {}
1577 if (rgwrados
->get_use_datacache()) {
1578 const std::lock_guard
l(d3n_get_data
.d3n_lock
);
1582 D3nGetObjData d3n_get_data
;
1583 std::atomic_bool d3n_bypass_cache_write
{false};
1585 int flush(rgw::AioResultList
&& results
);
1588 // wait for all completions to drain and ignore the results
1593 auto c
= aio
->wait();
1594 while (!c
.empty()) {
1595 int r
= flush(std::move(c
));
1602 return flush(std::move(c
));