]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_bucket.h
import ceph quincy 17.2.6
[ceph.git] / ceph / src / rgw / rgw_bucket.h
CommitLineData
7c673cae 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
7c673cae 3
20effc67 4#pragma once
7c673cae
FG
5
6#include <string>
7#include <memory>
f67539c2
TL
8#include <variant>
9
10#include <boost/container/flat_map.hpp>
11#include <boost/container/flat_set.hpp>
7c673cae
FG
12
13#include "include/types.h"
14#include "rgw_common.h"
15#include "rgw_tools.h"
9f95a23c 16#include "rgw_metadata.h"
7c673cae
FG
17
18#include "rgw_string.h"
20effc67 19#include "rgw_sal.h"
7c673cae
FG
20
21#include "common/Formatter.h"
22#include "common/lru_map.h"
23#include "common/ceph_time.h"
9f95a23c 24
7c673cae
FG
25#include "rgw_formats.h"
26
9f95a23c
TL
27#include "services/svc_bucket_types.h"
28#include "services/svc_bucket_sync.h"
29
11fdf7f2 30// define as static when RGWBucket implementation completes
20effc67 31extern void rgw_get_buckets_obj(const rgw_user& user_id, std::string& buckets_obj_id);
7c673cae 32
9f95a23c
TL
33class RGWSI_Meta;
34class RGWBucketMetadataHandler;
35class RGWBucketInstanceMetadataHandler;
36class RGWUserCtl;
37class RGWBucketCtl;
f67539c2
TL
38class RGWZone;
39struct RGWZoneParams;
7c673cae 40
20effc67
TL
41extern void init_bucket(rgw_bucket *b, const char *t, const char *n, const char *dp, const char *ip, const char *m, const char *id);
42
43extern int rgw_bucket_parse_bucket_instance(const std::string& bucket_instance, std::string *bucket_name, std::string *bucket_id, int *shard_id);
44extern int rgw_bucket_parse_bucket_key(CephContext *cct, const std::string& key,
7c673cae
FG
45 rgw_bucket* bucket, int *shard_id);
46
7c673cae
FG
47extern std::string rgw_make_bucket_entry_name(const std::string& tenant_name,
48 const std::string& bucket_name);
7c673cae 49
39ae355f
TL
50[[nodiscard]] int rgw_parse_url_bucket(const std::string& bucket,
51 const std::string& auth_tenant,
52 std::string &tenant_name,
53 std::string &bucket_name);
54
55extern int rgw_chown_bucket_and_objects(rgw::sal::Store* store,
56 rgw::sal::Bucket* bucket,
57 rgw::sal::User* new_user,
58 const std::string& marker,
59 std::string *err_msg,
60 const DoutPrefixProvider *dpp,
61 optional_yield y);
7c673cae 62
9f95a23c 63// this is used as a filter to RGWRados::cls_bucket_list_ordered; it
20effc67
TL
64// conforms to the type RGWBucketListNameFilter
65extern bool rgw_bucket_object_check_filter(const std::string& oid);
9f95a23c 66
f67539c2
TL
67void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout,
68 const RGWZone& zone,
69 std::optional<uint32_t> shards,
70 std::optional<rgw::BucketIndexType> type);
71
7c673cae
FG
72struct RGWBucketCompleteInfo {
73 RGWBucketInfo info;
20effc67 74 std::map<std::string, bufferlist> attrs;
7c673cae
FG
75
76 void dump(Formatter *f) const;
77 void decode_json(JSONObj *obj);
78};
79
80class RGWBucketEntryMetadataObject : public RGWMetadataObject {
81 RGWBucketEntryPoint ep;
20effc67 82 std::map<std::string, bufferlist> attrs;
7c673cae 83public:
9f95a23c 84 RGWBucketEntryMetadataObject(RGWBucketEntryPoint& _ep, const obj_version& v, real_time m) : ep(_ep) {
7c673cae
FG
85 objv = v;
86 mtime = m;
9f95a23c
TL
87 set_pattrs (&attrs);
88 }
20effc67 89 RGWBucketEntryMetadataObject(RGWBucketEntryPoint& _ep, const obj_version& v, real_time m, std::map<std::string, bufferlist>&& _attrs) :
9f95a23c
TL
90 ep(_ep), attrs(std::move(_attrs)) {
91 objv = v;
92 mtime = m;
93 set_pattrs (&attrs);
7c673cae
FG
94 }
95
96 void dump(Formatter *f) const override {
97 ep.dump(f);
98 }
9f95a23c
TL
99
100 RGWBucketEntryPoint& get_ep() {
101 return ep;
102 }
103
20effc67 104 std::map<std::string, bufferlist>& get_attrs() {
9f95a23c
TL
105 return attrs;
106 }
7c673cae
FG
107};
108
109class RGWBucketInstanceMetadataObject : public RGWMetadataObject {
110 RGWBucketCompleteInfo info;
111public:
112 RGWBucketInstanceMetadataObject() {}
9f95a23c 113 RGWBucketInstanceMetadataObject(RGWBucketCompleteInfo& i, const obj_version& v, real_time m) : info(i) {
7c673cae
FG
114 objv = v;
115 mtime = m;
116 }
117
118 void dump(Formatter *f) const override {
119 info.dump(f);
120 }
121
122 void decode_json(JSONObj *obj) {
123 info.decode_json(obj);
124 }
125
9f95a23c
TL
126 RGWBucketCompleteInfo& get_bci() {
127 return info;
128 }
129 RGWBucketInfo& get_bucket_info() {
130 return info.info;
131 }
7c673cae
FG
132};
133
134/**
135 * Store a list of the user's buckets, with associated functinos.
136 */
20effc67 137class RGWUserBuckets {
3efd9988 138 std::map<std::string, RGWBucketEnt> buckets;
7c673cae
FG
139
140public:
3efd9988
FG
141 RGWUserBuckets() = default;
142 RGWUserBuckets(RGWUserBuckets&&) = default;
143
144 RGWUserBuckets& operator=(const RGWUserBuckets&) = default;
145
7c673cae 146 void encode(bufferlist& bl) const {
11fdf7f2
TL
147 using ceph::encode;
148 encode(buckets, bl);
7c673cae 149 }
11fdf7f2
TL
150 void decode(bufferlist::const_iterator& bl) {
151 using ceph::decode;
152 decode(buckets, bl);
7c673cae
FG
153 }
154 /**
155 * Check if the user owns a bucket by the given name.
156 */
20effc67
TL
157 bool owns(std::string& name) {
158 std::map<std::string, RGWBucketEnt>::iterator iter;
7c673cae
FG
159 iter = buckets.find(name);
160 return (iter != buckets.end());
161 }
162
163 /**
164 * Add a (created) bucket to the user's bucket list.
165 */
166 void add(const RGWBucketEnt& bucket) {
167 buckets[bucket.bucket.name] = bucket;
168 }
169
170 /**
171 * Remove a bucket from the user's list by name.
172 */
20effc67
TL
173 void remove(const std::string& name) {
174 std::map<std::string, RGWBucketEnt>::iterator iter;
7c673cae
FG
175 iter = buckets.find(name);
176 if (iter != buckets.end()) {
177 buckets.erase(iter);
178 }
179 }
180
181 /**
182 * Get the user's buckets as a map.
183 */
20effc67 184 std::map<std::string, RGWBucketEnt>& get_buckets() { return buckets; }
7c673cae
FG
185
186 /**
187 * Cleanup data structure
188 */
189 void clear() { buckets.clear(); }
190
191 size_t count() { return buckets.size(); }
192};
193WRITE_CLASS_ENCODER(RGWUserBuckets)
194
9f95a23c
TL
195class RGWBucketMetadataHandlerBase : public RGWMetadataHandler_GenericMetaBE {
196public:
197 virtual ~RGWBucketMetadataHandlerBase() {}
198 virtual void init(RGWSI_Bucket *bucket_svc,
199 RGWBucketCtl *bucket_ctl) = 0;
200
201};
202
203class RGWBucketInstanceMetadataHandlerBase : public RGWMetadataHandler_GenericMetaBE {
204public:
205 virtual ~RGWBucketInstanceMetadataHandlerBase() {}
206 virtual void init(RGWSI_Zone *zone_svc,
207 RGWSI_Bucket *bucket_svc,
208 RGWSI_BucketIndex *bi_svc) = 0;
209};
11fdf7f2
TL
210
211class RGWBucketMetaHandlerAllocator {
212public:
9f95a23c 213 static RGWBucketMetadataHandlerBase *alloc();
11fdf7f2
TL
214};
215
216class RGWBucketInstanceMetaHandlerAllocator {
217public:
9f95a23c 218 static RGWBucketInstanceMetadataHandlerBase *alloc();
11fdf7f2
TL
219};
220
221class RGWArchiveBucketMetaHandlerAllocator {
222public:
9f95a23c 223 static RGWBucketMetadataHandlerBase *alloc();
11fdf7f2
TL
224};
225
226class RGWArchiveBucketInstanceMetaHandlerAllocator {
227public:
9f95a23c 228 static RGWBucketInstanceMetadataHandlerBase *alloc();
11fdf7f2 229};
7c673cae 230
20effc67 231extern int rgw_remove_object(const DoutPrefixProvider *dpp, rgw::sal::Store* store, rgw::sal::Bucket* bucket, rgw_obj_key& key);
9f95a23c 232
20effc67
TL
233extern int rgw_object_get_attr(rgw::sal::Store* store, rgw::sal::Object* obj,
234 const char* attr_name, bufferlist& out_bl,
235 optional_yield y);
9f95a23c 236
39ae355f 237extern void check_bad_user_bucket_mapping(rgw::sal::Store* store, rgw::sal::User& user, bool fix, optional_yield y, const DoutPrefixProvider *dpp);
7c673cae
FG
238
239struct RGWBucketAdminOpState {
240 rgw_user uid;
241 std::string display_name;
242 std::string bucket_name;
243 std::string bucket_id;
244 std::string object_name;
9f95a23c 245 std::string new_bucket_name;
7c673cae
FG
246
247 bool list_buckets;
248 bool stat_buckets;
249 bool check_objects;
250 bool fix_index;
251 bool delete_child_objects;
252 bool bucket_stored;
9f95a23c 253 bool sync_bucket;
11fdf7f2 254 int max_aio = 0;
7c673cae 255
20effc67 256 std::unique_ptr<rgw::sal::Bucket> bucket;
7c673cae 257
94b18763 258 RGWQuotaInfo quota;
20effc67 259 RGWRateLimitInfo ratelimit_info;
94b18763 260
7c673cae
FG
261 void set_fetch_stats(bool value) { stat_buckets = value; }
262 void set_check_objects(bool value) { check_objects = value; }
263 void set_fix_index(bool value) { fix_index = value; }
264 void set_delete_children(bool value) { delete_child_objects = value; }
265
266 void set_max_aio(int value) { max_aio = value; }
267
31f18b77 268 void set_user_id(const rgw_user& user_id) {
7c673cae
FG
269 if (!user_id.empty())
270 uid = user_id;
271 }
9f95a23c
TL
272 void set_tenant(const std::string& tenant_str) {
273 uid.tenant = tenant_str;
274 }
31f18b77 275 void set_bucket_name(const std::string& bucket_str) {
7c673cae
FG
276 bucket_name = bucket_str;
277 }
278 void set_object(std::string& object_str) {
279 object_name = object_str;
280 }
9f95a23c
TL
281 void set_new_bucket_name(std::string& new_bucket_str) {
282 new_bucket_name = new_bucket_str;
283 }
94b18763
FG
284 void set_quota(RGWQuotaInfo& value) {
285 quota = value;
286 }
20effc67
TL
287 void set_bucket_ratelimit(RGWRateLimitInfo& value) {
288 ratelimit_info = value;
289 }
94b18763 290
7c673cae 291
9f95a23c
TL
292 void set_sync_bucket(bool value) { sync_bucket = value; }
293
7c673cae
FG
294 rgw_user& get_user_id() { return uid; }
295 std::string& get_user_display_name() { return display_name; }
296 std::string& get_bucket_name() { return bucket_name; }
297 std::string& get_object_name() { return object_name; }
9f95a23c 298 std::string& get_tenant() { return uid.tenant; }
7c673cae 299
20effc67
TL
300 rgw::sal::Bucket* get_bucket() { return bucket.get(); }
301 void set_bucket(std::unique_ptr<rgw::sal::Bucket> _bucket) {
302 bucket = std::move(_bucket);
7c673cae
FG
303 bucket_stored = true;
304 }
305
20effc67 306 void set_bucket_id(const std::string& bi) {
7c673cae
FG
307 bucket_id = bi;
308 }
20effc67 309 const std::string& get_bucket_id() { return bucket_id; }
7c673cae
FG
310
311 bool will_fetch_stats() { return stat_buckets; }
312 bool will_fix_index() { return fix_index; }
313 bool will_delete_children() { return delete_child_objects; }
314 bool will_check_objects() { return check_objects; }
315 bool is_user_op() { return !uid.empty(); }
316 bool is_system_op() { return uid.empty(); }
317 bool has_bucket_stored() { return bucket_stored; }
318 int get_max_aio() { return max_aio; }
9f95a23c 319 bool will_sync_bucket() { return sync_bucket; }
7c673cae
FG
320
321 RGWBucketAdminOpState() : list_buckets(false), stat_buckets(false), check_objects(false),
322 fix_index(false), delete_child_objects(false),
9f95a23c 323 bucket_stored(false), sync_bucket(true) {}
7c673cae
FG
324};
325
20effc67 326
7c673cae
FG
327/*
328 * A simple wrapper class for administrative bucket operations
329 */
20effc67 330class RGWBucket {
7c673cae 331 RGWUserBuckets buckets;
20effc67 332 rgw::sal::Store* store;
7c673cae
FG
333 RGWAccessHandle handle;
334
20effc67
TL
335 std::unique_ptr<rgw::sal::Bucket> bucket;
336 std::unique_ptr<rgw::sal::User> user;
7c673cae
FG
337
338 bool failure;
339
9f95a23c 340 RGWObjVersionTracker ep_objv; // entrypoint object version
7c673cae
FG
341
342public:
343 RGWBucket() : store(NULL), handle(NULL), failure(false) {}
20effc67
TL
344 int init(rgw::sal::Store* storage, RGWBucketAdminOpState& op_state, optional_yield y,
345 const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
7c673cae
FG
346
347 int check_bad_index_multipart(RGWBucketAdminOpState& op_state,
b3b6e05e
TL
348 RGWFormatterFlusher& flusher,
349 const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
7c673cae 350
b3b6e05e
TL
351 int check_object_index(const DoutPrefixProvider *dpp,
352 RGWBucketAdminOpState& op_state,
7c673cae 353 RGWFormatterFlusher& flusher,
9f95a23c 354 optional_yield y,
7c673cae
FG
355 std::string *err_msg = NULL);
356
b3b6e05e
TL
357 int check_index(const DoutPrefixProvider *dpp,
358 RGWBucketAdminOpState& op_state,
20effc67
TL
359 std::map<RGWObjCategory, RGWStorageStats>& existing_stats,
360 std::map<RGWObjCategory, RGWStorageStats>& calculated_stats,
7c673cae
FG
361 std::string *err_msg = NULL);
362
20effc67 363 int chown(RGWBucketAdminOpState& op_state, const std::string& marker,
b3b6e05e 364 optional_yield y, const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
b3b6e05e 365 int set_quota(RGWBucketAdminOpState& op_state, const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
7c673cae 366
b3b6e05e 367 int remove_object(const DoutPrefixProvider *dpp, RGWBucketAdminOpState& op_state, std::string *err_msg = NULL);
20effc67 368 int policy_bl_to_stream(bufferlist& bl, std::ostream& o);
b3b6e05e 369 int get_policy(RGWBucketAdminOpState& op_state, RGWAccessControlPolicy& policy, optional_yield y, const DoutPrefixProvider *dpp);
20effc67 370 int sync(RGWBucketAdminOpState& op_state, const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
7c673cae
FG
371
372 void clear_failure() { failure = false; }
81eedcae 373
20effc67 374 const RGWBucketInfo& get_bucket_info() const { return bucket->get_info(); }
7c673cae
FG
375};
376
20effc67 377class RGWBucketAdminOp {
7c673cae 378public:
20effc67 379 static int get_policy(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
b3b6e05e 380 RGWFormatterFlusher& flusher, const DoutPrefixProvider *dpp);
20effc67 381 static int get_policy(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
b3b6e05e 382 RGWAccessControlPolicy& policy, const DoutPrefixProvider *dpp);
20effc67
TL
383 static int dump_s3_policy(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
384 std::ostream& os, const DoutPrefixProvider *dpp);
7c673cae 385
20effc67
TL
386 static int unlink(rgw::sal::Store* store, RGWBucketAdminOpState& op_state, const DoutPrefixProvider *dpp);
387 static int link(rgw::sal::Store* store, RGWBucketAdminOpState& op_state, const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
388 static int chown(rgw::sal::Store* store, RGWBucketAdminOpState& op_state, const std::string& marker, const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
7c673cae 389
20effc67 390 static int check_index(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
b3b6e05e 391 RGWFormatterFlusher& flusher, optional_yield y, const DoutPrefixProvider *dpp);
7c673cae 392
20effc67
TL
393 static int remove_bucket(rgw::sal::Store* store, RGWBucketAdminOpState& op_state, optional_yield y,
394 const DoutPrefixProvider *dpp, bool bypass_gc = false, bool keep_index_consistent = true);
395 static int remove_object(rgw::sal::Store* store, RGWBucketAdminOpState& op_state, const DoutPrefixProvider *dpp);
396 static int info(rgw::sal::Store* store, RGWBucketAdminOpState& op_state, RGWFormatterFlusher& flusher, optional_yield y, const DoutPrefixProvider *dpp);
397 static int limit_check(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
7c673cae 398 const std::list<std::string>& user_ids,
f67539c2 399 RGWFormatterFlusher& flusher, optional_yield y,
b3b6e05e 400 const DoutPrefixProvider *dpp,
7c673cae 401 bool warnings_only = false);
20effc67 402 static int set_quota(rgw::sal::Store* store, RGWBucketAdminOpState& op_state, const DoutPrefixProvider *dpp);
f64942e4 403
20effc67 404 static int list_stale_instances(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
b3b6e05e 405 RGWFormatterFlusher& flusher, const DoutPrefixProvider *dpp);
f64942e4 406
20effc67 407 static int clear_stale_instances(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
b3b6e05e 408 RGWFormatterFlusher& flusher, const DoutPrefixProvider *dpp);
20effc67 409 static int fix_lc_shards(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
b3b6e05e 410 RGWFormatterFlusher& flusher, const DoutPrefixProvider *dpp);
20effc67 411 static int fix_obj_expiry(rgw::sal::Store* store, RGWBucketAdminOpState& op_state,
b3b6e05e 412 RGWFormatterFlusher& flusher, const DoutPrefixProvider *dpp, bool dry_run = false);
9f95a23c 413
20effc67 414 static int sync_bucket(rgw::sal::Store* store, RGWBucketAdminOpState& op_state, const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
7c673cae
FG
415};
416
9f95a23c
TL
417struct rgw_ep_info {
418 RGWBucketEntryPoint &ep;
20effc67 419 std::map<std::string, buffer::list>& attrs;
9f95a23c 420 RGWObjVersionTracker ep_objv;
20effc67 421 rgw_ep_info(RGWBucketEntryPoint &ep, std::map<std::string, bufferlist>& attrs)
9f95a23c
TL
422 : ep(ep), attrs(attrs) {}
423};
424
20effc67 425class RGWBucketCtl {
9f95a23c
TL
426 CephContext *cct;
427
428 struct Svc {
429 RGWSI_Zone *zone{nullptr};
430 RGWSI_Bucket *bucket{nullptr};
431 RGWSI_Bucket_Sync *bucket_sync{nullptr};
432 RGWSI_BucketIndex *bi{nullptr};
433 } svc;
434
435 struct Ctl {
436 RGWUserCtl *user{nullptr};
437 } ctl;
438
439 RGWBucketMetadataHandler *bm_handler;
440 RGWBucketInstanceMetadataHandler *bmi_handler;
441
442 RGWSI_Bucket_BE_Handler bucket_be_handler; /* bucket backend handler */
443 RGWSI_BucketInstance_BE_Handler bi_be_handler; /* bucket instance backend handler */
444
445 int call(std::function<int(RGWSI_Bucket_X_Ctx& ctx)> f);
446
9f95a23c
TL
447public:
448 RGWBucketCtl(RGWSI_Zone *zone_svc,
449 RGWSI_Bucket *bucket_svc,
450 RGWSI_Bucket_Sync *bucket_sync_svc,
451 RGWSI_BucketIndex *bi_svc);
452
453 void init(RGWUserCtl *user_ctl,
454 RGWBucketMetadataHandler *_bm_handler,
455 RGWBucketInstanceMetadataHandler *_bmi_handler,
b3b6e05e
TL
456 RGWDataChangesLog *datalog,
457 const DoutPrefixProvider *dpp);
9f95a23c
TL
458
459 struct Bucket {
460 struct GetParams {
461 RGWObjVersionTracker *objv_tracker{nullptr};
462 real_time *mtime{nullptr};
20effc67 463 std::map<std::string, bufferlist> *attrs{nullptr};
9f95a23c
TL
464 rgw_cache_entry_info *cache_info{nullptr};
465 boost::optional<obj_version> refresh_version;
466 std::optional<RGWSI_MetaBackend_CtxParams> bectx_params;
467
468 GetParams() {}
469
470 GetParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
471 objv_tracker = _objv_tracker;
472 return *this;
473 }
474
475 GetParams& set_mtime(ceph::real_time *_mtime) {
476 mtime = _mtime;
477 return *this;
478 }
479
20effc67 480 GetParams& set_attrs(std::map<std::string, bufferlist> *_attrs) {
9f95a23c
TL
481 attrs = _attrs;
482 return *this;
483 }
484
485 GetParams& set_cache_info(rgw_cache_entry_info *_cache_info) {
486 cache_info = _cache_info;
487 return *this;
488 }
489
490 GetParams& set_refresh_version(const obj_version& _refresh_version) {
491 refresh_version = _refresh_version;
492 return *this;
493 }
494
495 GetParams& set_bectx_params(std::optional<RGWSI_MetaBackend_CtxParams> _bectx_params) {
496 bectx_params = _bectx_params;
497 return *this;
498 }
499 };
500
501 struct PutParams {
502 RGWObjVersionTracker *objv_tracker{nullptr};
503 ceph::real_time mtime;
504 bool exclusive{false};
20effc67 505 std::map<std::string, bufferlist> *attrs{nullptr};
9f95a23c
TL
506
507 PutParams() {}
508
509 PutParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
510 objv_tracker = _objv_tracker;
511 return *this;
512 }
513
514 PutParams& set_mtime(const ceph::real_time& _mtime) {
515 mtime = _mtime;
516 return *this;
517 }
518
519 PutParams& set_exclusive(bool _exclusive) {
520 exclusive = _exclusive;
521 return *this;
522 }
523
20effc67 524 PutParams& set_attrs(std::map<std::string, bufferlist> *_attrs) {
9f95a23c
TL
525 attrs = _attrs;
526 return *this;
527 }
528 };
529
530 struct RemoveParams {
531 RGWObjVersionTracker *objv_tracker{nullptr};
532
533 RemoveParams() {}
534
535 RemoveParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
536 objv_tracker = _objv_tracker;
537 return *this;
538 }
539 };
540 };
541
542 struct BucketInstance {
543 struct GetParams {
544 real_time *mtime{nullptr};
20effc67 545 std::map<std::string, bufferlist> *attrs{nullptr};
9f95a23c
TL
546 rgw_cache_entry_info *cache_info{nullptr};
547 boost::optional<obj_version> refresh_version;
548 RGWObjVersionTracker *objv_tracker{nullptr};
549 std::optional<RGWSI_MetaBackend_CtxParams> bectx_params;
550
551 GetParams() {}
552
553 GetParams& set_mtime(ceph::real_time *_mtime) {
554 mtime = _mtime;
555 return *this;
556 }
557
20effc67 558 GetParams& set_attrs(std::map<std::string, bufferlist> *_attrs) {
9f95a23c
TL
559 attrs = _attrs;
560 return *this;
561 }
562
563 GetParams& set_cache_info(rgw_cache_entry_info *_cache_info) {
564 cache_info = _cache_info;
565 return *this;
566 }
567
568 GetParams& set_refresh_version(const obj_version& _refresh_version) {
569 refresh_version = _refresh_version;
570 return *this;
571 }
572
573 GetParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
574 objv_tracker = _objv_tracker;
575 return *this;
576 }
577
578 GetParams& set_bectx_params(std::optional<RGWSI_MetaBackend_CtxParams> _bectx_params) {
579 bectx_params = _bectx_params;
580 return *this;
581 }
582 };
583
584 struct PutParams {
585 std::optional<RGWBucketInfo *> orig_info; /* nullopt: orig_info was not fetched,
586 nullptr: orig_info was not found (new bucket instance */
587 ceph::real_time mtime;
588 bool exclusive{false};
20effc67 589 std::map<std::string, bufferlist> *attrs{nullptr};
9f95a23c
TL
590 RGWObjVersionTracker *objv_tracker{nullptr};
591
592 PutParams() {}
593
594 PutParams& set_orig_info(RGWBucketInfo *pinfo) {
595 orig_info = pinfo;
596 return *this;
597 }
598
599 PutParams& set_mtime(const ceph::real_time& _mtime) {
600 mtime = _mtime;
601 return *this;
602 }
603
604 PutParams& set_exclusive(bool _exclusive) {
605 exclusive = _exclusive;
606 return *this;
607 }
608
20effc67 609 PutParams& set_attrs(std::map<std::string, bufferlist> *_attrs) {
9f95a23c
TL
610 attrs = _attrs;
611 return *this;
612 }
613
614 PutParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
615 objv_tracker = _objv_tracker;
616 return *this;
617 }
618 };
619
620 struct RemoveParams {
621 RGWObjVersionTracker *objv_tracker{nullptr};
622
623 RemoveParams() {}
624
625 RemoveParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
626 objv_tracker = _objv_tracker;
627 return *this;
628 }
629 };
630 };
631
632 /* bucket entrypoint */
633 int read_bucket_entrypoint_info(const rgw_bucket& bucket,
634 RGWBucketEntryPoint *info,
635 optional_yield y,
b3b6e05e 636 const DoutPrefixProvider *dpp,
9f95a23c
TL
637 const Bucket::GetParams& params = {});
638 int store_bucket_entrypoint_info(const rgw_bucket& bucket,
639 RGWBucketEntryPoint& info,
640 optional_yield y,
b3b6e05e 641 const DoutPrefixProvider *dpp,
9f95a23c
TL
642 const Bucket::PutParams& params = {});
643 int remove_bucket_entrypoint_info(const rgw_bucket& bucket,
644 optional_yield y,
b3b6e05e 645 const DoutPrefixProvider *dpp,
9f95a23c
TL
646 const Bucket::RemoveParams& params = {});
647
648 /* bucket instance */
649 int read_bucket_instance_info(const rgw_bucket& bucket,
650 RGWBucketInfo *info,
651 optional_yield y,
b3b6e05e 652 const DoutPrefixProvider *dpp,
9f95a23c
TL
653 const BucketInstance::GetParams& params = {});
654 int store_bucket_instance_info(const rgw_bucket& bucket,
655 RGWBucketInfo& info,
656 optional_yield y,
b3b6e05e 657 const DoutPrefixProvider *dpp,
9f95a23c
TL
658 const BucketInstance::PutParams& params = {});
659 int remove_bucket_instance_info(const rgw_bucket& bucket,
660 RGWBucketInfo& info,
661 optional_yield y,
b3b6e05e 662 const DoutPrefixProvider *dpp,
9f95a23c
TL
663 const BucketInstance::RemoveParams& params = {});
664
665 /*
666 * bucket_id may or may not be provided
667 *
668 * ep_objv_tracker might not be populated even if provided. Will only be set if entrypoint is read
669 * (that is: if bucket_id is empty).
670 */
671 int read_bucket_info(const rgw_bucket& bucket,
672 RGWBucketInfo *info,
673 optional_yield y,
b3b6e05e 674 const DoutPrefixProvider *dpp,
9f95a23c
TL
675 const BucketInstance::GetParams& params = {},
676 RGWObjVersionTracker *ep_objv_tracker = nullptr);
677
678
679 int set_bucket_instance_attrs(RGWBucketInfo& bucket_info,
20effc67 680 std::map<std::string, bufferlist>& attrs,
9f95a23c 681 RGWObjVersionTracker *objv_tracker,
b3b6e05e
TL
682 optional_yield y,
683 const DoutPrefixProvider *dpp);
9f95a23c
TL
684
685 /* user/bucket */
686 int link_bucket(const rgw_user& user_id,
687 const rgw_bucket& bucket,
688 ceph::real_time creation_time,
689 optional_yield y,
b3b6e05e 690 const DoutPrefixProvider *dpp,
9f95a23c
TL
691 bool update_entrypoint = true,
692 rgw_ep_info *pinfo = nullptr);
693
694 int unlink_bucket(const rgw_user& user_id,
695 const rgw_bucket& bucket,
696 optional_yield y,
b3b6e05e 697 const DoutPrefixProvider *dpp,
9f95a23c
TL
698 bool update_entrypoint = true);
699
20effc67 700 int read_buckets_stats(std::map<std::string, RGWBucketEnt>& m,
b3b6e05e
TL
701 optional_yield y,
702 const DoutPrefixProvider *dpp);
9f95a23c
TL
703
704 int read_bucket_stats(const rgw_bucket& bucket,
705 RGWBucketEnt *result,
b3b6e05e
TL
706 optional_yield y,
707 const DoutPrefixProvider *dpp);
9f95a23c
TL
708
709 /* quota related */
b3b6e05e
TL
710 int sync_user_stats(const DoutPrefixProvider *dpp,
711 const rgw_user& user_id, const RGWBucketInfo& bucket_info,
f67539c2 712 optional_yield y,
20effc67 713 RGWBucketEnt* pent);
9f95a23c
TL
714
715 /* bucket sync */
716 int get_sync_policy_handler(std::optional<rgw_zone_id> zone,
717 std::optional<rgw_bucket> bucket,
718 RGWBucketSyncPolicyHandlerRef *phandler,
b3b6e05e
TL
719 optional_yield y,
720 const DoutPrefixProvider *dpp);
9f95a23c 721 int bucket_exports_data(const rgw_bucket& bucket,
b3b6e05e
TL
722 optional_yield y,
723 const DoutPrefixProvider *dpp);
9f95a23c 724 int bucket_imports_data(const rgw_bucket& bucket,
b3b6e05e
TL
725 optional_yield y,
726 const DoutPrefixProvider *dpp);
9f95a23c
TL
727
728private:
729 int convert_old_bucket_info(RGWSI_Bucket_X_Ctx& ctx,
730 const rgw_bucket& bucket,
b3b6e05e
TL
731 optional_yield y,
732 const DoutPrefixProvider *dpp);
9f95a23c
TL
733
734 int do_store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
735 const rgw_bucket& bucket,
736 RGWBucketInfo& info,
737 optional_yield y,
b3b6e05e 738 const DoutPrefixProvider *dpp,
9f95a23c
TL
739 const BucketInstance::PutParams& params);
740
741 int do_store_linked_bucket_info(RGWSI_Bucket_X_Ctx& ctx,
742 RGWBucketInfo& info,
743 RGWBucketInfo *orig_info,
744 bool exclusive, real_time mtime,
745 obj_version *pep_objv,
20effc67 746 std::map<std::string, bufferlist> *pattrs,
9f95a23c 747 bool create_entry_point,
b3b6e05e
TL
748 optional_yield,
749 const DoutPrefixProvider *dpp);
9f95a23c
TL
750
751 int do_link_bucket(RGWSI_Bucket_EP_Ctx& ctx,
752 const rgw_user& user,
753 const rgw_bucket& bucket,
754 ceph::real_time creation_time,
9f95a23c 755 bool update_entrypoint,
f67539c2 756 rgw_ep_info *pinfo,
b3b6e05e
TL
757 optional_yield y,
758 const DoutPrefixProvider *dpp);
9f95a23c
TL
759
760 int do_unlink_bucket(RGWSI_Bucket_EP_Ctx& ctx,
761 const rgw_user& user_id,
762 const rgw_bucket& bucket,
f67539c2 763 bool update_entrypoint,
b3b6e05e
TL
764 optional_yield y,
765 const DoutPrefixProvider *dpp);
9f95a23c 766
7c673cae
FG
767};
768
20effc67
TL
769bool rgw_find_bucket_by_id(const DoutPrefixProvider *dpp, CephContext *cct, rgw::sal::Store* store, const std::string& marker,
770 const std::string& bucket_id, rgw_bucket* bucket_out);