]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_sal_rados.h
4e4673c032806dce1026a9e29af5287defe541e5
[ceph.git] / ceph / src / rgw / rgw_sal_rados.h
1
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2020 Red Hat, Inc.
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 *
14 */
15
16 #pragma once
17
18 #include "rgw_sal.h"
19 #include "rgw_rados.h"
20 #include "rgw_notify.h"
21 #include "rgw_oidc_provider.h"
22 #include "rgw_role.h"
23 #include "rgw_multi.h"
24 #include "rgw_putobj_processor.h"
25 #include "services/svc_tier_rados.h"
26 #include "cls/lock/cls_lock_client.h"
27
28 namespace rgw { namespace sal {
29
30 class RadosStore;
31 class RadosMultipartUpload;
32
33 class RadosCompletions : public Completions {
34 public:
35 std::list<librados::AioCompletion*> handles;
36 RadosCompletions() {}
37 ~RadosCompletions() = default;
38 virtual int drain() override;
39 };
40
41 class RadosUser : public User {
42 private:
43 RadosStore* store;
44
45 public:
46 RadosUser(RadosStore *_st, const rgw_user& _u) : User(_u), store(_st) { }
47 RadosUser(RadosStore *_st, const RGWUserInfo& _i) : User(_i), store(_st) { }
48 RadosUser(RadosStore *_st) : store(_st) { }
49 RadosUser(RadosUser& _o) = default;
50 RadosUser() {}
51
52 virtual std::unique_ptr<User> clone() override {
53 return std::unique_ptr<User>(new RadosUser(*this));
54 }
55 int list_buckets(const DoutPrefixProvider* dpp, const std::string& marker, const std::string& end_marker,
56 uint64_t max, bool need_stats, BucketList& buckets,
57 optional_yield y) override;
58 virtual int create_bucket(const DoutPrefixProvider* dpp,
59 const rgw_bucket& b,
60 const std::string& zonegroup_id,
61 rgw_placement_rule& placement_rule,
62 std::string& swift_ver_location,
63 const RGWQuotaInfo * pquota_info,
64 const RGWAccessControlPolicy& policy,
65 Attrs& attrs,
66 RGWBucketInfo& info,
67 obj_version& ep_objv,
68 bool exclusive,
69 bool obj_lock_enabled,
70 bool* existed,
71 req_info& req_info,
72 std::unique_ptr<Bucket>* bucket,
73 optional_yield y) override;
74 virtual int read_attrs(const DoutPrefixProvider* dpp, optional_yield y) override;
75 virtual int merge_and_store_attrs(const DoutPrefixProvider* dpp, Attrs& new_attrs, optional_yield y) override;
76 virtual int read_stats(const DoutPrefixProvider *dpp,
77 optional_yield y, RGWStorageStats* stats,
78 ceph::real_time* last_stats_sync = nullptr,
79 ceph::real_time* last_stats_update = nullptr) override;
80 virtual int read_stats_async(const DoutPrefixProvider *dpp, RGWGetUserStats_CB* cb) override;
81 virtual int complete_flush_stats(const DoutPrefixProvider *dpp, optional_yield y) override;
82 virtual int read_usage(const DoutPrefixProvider *dpp, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries,
83 bool* is_truncated, RGWUsageIter& usage_iter,
84 std::map<rgw_user_bucket, rgw_usage_log_entry>& usage) override;
85 virtual int trim_usage(const DoutPrefixProvider *dpp, uint64_t start_epoch, uint64_t end_epoch) override;
86
87 virtual int load_user(const DoutPrefixProvider* dpp, optional_yield y) override;
88 virtual int store_user(const DoutPrefixProvider* dpp, optional_yield y, bool exclusive, RGWUserInfo* old_info = nullptr) override;
89 virtual int remove_user(const DoutPrefixProvider* dpp, optional_yield y) override;
90
91 friend class RadosBucket;
92 };
93
94 class RadosObject : public Object {
95 private:
96 RadosStore* store;
97 RGWAccessControlPolicy acls;
98
99 public:
100
101 struct RadosReadOp : public ReadOp {
102 private:
103 RadosObject* source;
104 RGWObjectCtx* rctx;
105 RGWRados::Object op_target;
106 RGWRados::Object::Read parent_op;
107
108 public:
109 RadosReadOp(RadosObject *_source, RGWObjectCtx *_rctx);
110
111 virtual int prepare(optional_yield y, const DoutPrefixProvider* dpp) override;
112 virtual int read(int64_t ofs, int64_t end, bufferlist& bl, optional_yield y, const DoutPrefixProvider* dpp) override;
113 virtual int iterate(const DoutPrefixProvider* dpp, int64_t ofs, int64_t end, RGWGetDataCB* cb, optional_yield y) override;
114 virtual int get_attr(const DoutPrefixProvider* dpp, const char* name, bufferlist& dest, optional_yield y) override;
115 };
116
117 struct RadosDeleteOp : public DeleteOp {
118 private:
119 RadosObject* source;
120 RGWObjectCtx* rctx;
121 RGWRados::Object op_target;
122 RGWRados::Object::Delete parent_op;
123
124 public:
125 RadosDeleteOp(RadosObject* _source, RGWObjectCtx* _rctx);
126
127 virtual int delete_obj(const DoutPrefixProvider* dpp, optional_yield y) override;
128 };
129
130 RadosObject() = default;
131
132 RadosObject(RadosStore *_st, const rgw_obj_key& _k)
133 : Object(_k),
134 store(_st),
135 acls() {
136 }
137 RadosObject(RadosStore *_st, const rgw_obj_key& _k, Bucket* _b)
138 : Object(_k, _b),
139 store(_st),
140 acls() {
141 }
142 RadosObject(RadosObject& _o) = default;
143
144 virtual ~RadosObject();
145
146 virtual int delete_object(const DoutPrefixProvider* dpp, RGWObjectCtx* obj_ctx,
147 optional_yield y, bool prevent_versioning) override;
148 virtual int delete_obj_aio(const DoutPrefixProvider* dpp, RGWObjState* astate, Completions* aio,
149 bool keep_index_consistent, optional_yield y) override;
150 virtual int copy_object(RGWObjectCtx& obj_ctx, User* user,
151 req_info* info, const rgw_zone_id& source_zone,
152 rgw::sal::Object* dest_object, rgw::sal::Bucket* dest_bucket,
153 rgw::sal::Bucket* src_bucket,
154 const rgw_placement_rule& dest_placement,
155 ceph::real_time* src_mtime, ceph::real_time* mtime,
156 const ceph::real_time* mod_ptr, const ceph::real_time* unmod_ptr,
157 bool high_precision_time,
158 const char* if_match, const char* if_nomatch,
159 AttrsMod attrs_mod, bool copy_if_newer, Attrs& attrs,
160 RGWObjCategory category, uint64_t olh_epoch,
161 boost::optional<ceph::real_time> delete_at,
162 std::string* version_id, std::string* tag, std::string* etag,
163 void (*progress_cb)(off_t, void *), void* progress_data,
164 const DoutPrefixProvider* dpp, optional_yield y) override;
165 virtual RGWAccessControlPolicy& get_acl(void) override { return acls; }
166 virtual int set_acl(const RGWAccessControlPolicy& acl) override { acls = acl; return 0; }
167 virtual void set_atomic(RGWObjectCtx* rctx) const override;
168 virtual void set_prefetch_data(RGWObjectCtx* rctx) override;
169 virtual void set_compressed(RGWObjectCtx* rctx) override;
170
171 virtual int get_obj_state(const DoutPrefixProvider* dpp, RGWObjectCtx* rctx, RGWObjState **state, optional_yield y, bool follow_olh = true) override;
172 virtual int set_obj_attrs(const DoutPrefixProvider* dpp, RGWObjectCtx* rctx, Attrs* setattrs, Attrs* delattrs, optional_yield y, rgw_obj* target_obj = NULL) override;
173 virtual int get_obj_attrs(RGWObjectCtx* rctx, optional_yield y, const DoutPrefixProvider* dpp, rgw_obj* target_obj = NULL) override;
174 virtual int modify_obj_attrs(RGWObjectCtx* rctx, const char* attr_name, bufferlist& attr_val, optional_yield y, const DoutPrefixProvider* dpp) override;
175 virtual int delete_obj_attrs(const DoutPrefixProvider* dpp, RGWObjectCtx* rctx, const char* attr_name, optional_yield y) override;
176 virtual bool is_expired() override;
177 virtual void gen_rand_obj_instance_name() override;
178 void get_raw_obj(rgw_raw_obj* raw_obj);
179 virtual std::unique_ptr<Object> clone() override {
180 return std::unique_ptr<Object>(new RadosObject(*this));
181 }
182 virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) override;
183 virtual int transition(RGWObjectCtx& rctx,
184 Bucket* bucket,
185 const rgw_placement_rule& placement_rule,
186 const real_time& mtime,
187 uint64_t olh_epoch,
188 const DoutPrefixProvider* dpp,
189 optional_yield y) override;
190 virtual bool placement_rules_match(rgw_placement_rule& r1, rgw_placement_rule& r2) override;
191 virtual int dump_obj_layout(const DoutPrefixProvider *dpp, optional_yield y, Formatter* f, RGWObjectCtx* obj_ctx) override;
192
193 /* Swift versioning */
194 virtual int swift_versioning_restore(RGWObjectCtx* obj_ctx,
195 bool& restored,
196 const DoutPrefixProvider* dpp) override;
197 virtual int swift_versioning_copy(RGWObjectCtx* obj_ctx,
198 const DoutPrefixProvider* dpp,
199 optional_yield y) override;
200
201 /* OPs */
202 virtual std::unique_ptr<ReadOp> get_read_op(RGWObjectCtx *) override;
203 virtual std::unique_ptr<DeleteOp> get_delete_op(RGWObjectCtx*) override;
204
205 /* OMAP */
206 virtual int omap_get_vals(const DoutPrefixProvider *dpp, const std::string& marker, uint64_t count,
207 std::map<std::string, bufferlist> *m,
208 bool* pmore, optional_yield y) override;
209 virtual int omap_get_all(const DoutPrefixProvider *dpp, std::map<std::string, bufferlist> *m,
210 optional_yield y) override;
211 virtual int omap_get_vals_by_keys(const DoutPrefixProvider *dpp, const std::string& oid,
212 const std::set<std::string>& keys,
213 Attrs* vals) override;
214 virtual int omap_set_val_by_key(const DoutPrefixProvider *dpp, const std::string& key, bufferlist& val,
215 bool must_exist, optional_yield y) override;
216
217 /* Internal to RadosStore */
218 int get_max_chunk_size(const DoutPrefixProvider* dpp,
219 rgw_placement_rule placement_rule,
220 uint64_t* max_chunk_size,
221 uint64_t* alignment = nullptr);
222 void get_max_aligned_size(uint64_t size, uint64_t alignment, uint64_t* max_size);
223 void raw_obj_to_obj(const rgw_raw_obj& raw_obj);
224
225 private:
226 int read_attrs(const DoutPrefixProvider* dpp, RGWRados::Object::Read &read_op, optional_yield y, rgw_obj* target_obj = nullptr);
227 };
228
229 class RadosBucket : public Bucket {
230 private:
231 RadosStore* store;
232 RGWAccessControlPolicy acls;
233
234 public:
235 RadosBucket(RadosStore *_st)
236 : store(_st),
237 acls() {
238 }
239
240 RadosBucket(RadosStore *_st, User* _u)
241 : Bucket(_u),
242 store(_st),
243 acls() {
244 }
245
246 RadosBucket(RadosStore *_st, const rgw_bucket& _b)
247 : Bucket(_b),
248 store(_st),
249 acls() {
250 }
251
252 RadosBucket(RadosStore *_st, const RGWBucketEnt& _e)
253 : Bucket(_e),
254 store(_st),
255 acls() {
256 }
257
258 RadosBucket(RadosStore *_st, const RGWBucketInfo& _i)
259 : Bucket(_i),
260 store(_st),
261 acls() {
262 }
263
264 RadosBucket(RadosStore *_st, const rgw_bucket& _b, User* _u)
265 : Bucket(_b, _u),
266 store(_st),
267 acls() {
268 }
269
270 RadosBucket(RadosStore *_st, const RGWBucketEnt& _e, User* _u)
271 : Bucket(_e, _u),
272 store(_st),
273 acls() {
274 }
275
276 RadosBucket(RadosStore *_st, const RGWBucketInfo& _i, User* _u)
277 : Bucket(_i, _u),
278 store(_st),
279 acls() {
280 }
281
282 virtual ~RadosBucket();
283
284 virtual std::unique_ptr<Object> get_object(const rgw_obj_key& k) override;
285 virtual int list(const DoutPrefixProvider* dpp, ListParams&, int, ListResults&, optional_yield y) override;
286 virtual int remove_bucket(const DoutPrefixProvider* dpp, bool delete_children, bool forward_to_master, req_info* req_info, optional_yield y) override;
287 virtual int remove_bucket_bypass_gc(int concurrent_max, bool
288 keep_index_consistent,
289 optional_yield y, const
290 DoutPrefixProvider *dpp) override;
291 virtual RGWAccessControlPolicy& get_acl(void) override { return acls; }
292 virtual int set_acl(const DoutPrefixProvider* dpp, RGWAccessControlPolicy& acl, optional_yield y) override;
293 virtual int load_bucket(const DoutPrefixProvider* dpp, optional_yield y, bool get_stats = false) override;
294 virtual int read_stats(const DoutPrefixProvider *dpp, int shard_id,
295 std::string* bucket_ver, std::string* master_ver,
296 std::map<RGWObjCategory, RGWStorageStats>& stats,
297 std::string* max_marker = nullptr,
298 bool* syncstopped = nullptr) override;
299 virtual int read_stats_async(const DoutPrefixProvider *dpp, int shard_id, RGWGetBucketStats_CB* ctx) override;
300 virtual int sync_user_stats(const DoutPrefixProvider *dpp, optional_yield y) override;
301 virtual int update_container_stats(const DoutPrefixProvider* dpp) override;
302 virtual int check_bucket_shards(const DoutPrefixProvider* dpp) override;
303 virtual int chown(const DoutPrefixProvider* dpp, User* new_user, User* old_user, optional_yield y, const std::string* marker = nullptr) override;
304 virtual int put_info(const DoutPrefixProvider* dpp, bool exclusive, ceph::real_time mtime) override;
305 virtual bool is_owner(User* user) override;
306 virtual int check_empty(const DoutPrefixProvider* dpp, optional_yield y) override;
307 virtual int check_quota(const DoutPrefixProvider *dpp, RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota, uint64_t obj_size, optional_yield y, bool check_size_only = false) override;
308 virtual int merge_and_store_attrs(const DoutPrefixProvider* dpp, Attrs& attrs, optional_yield y) override;
309 virtual int try_refresh_info(const DoutPrefixProvider* dpp, ceph::real_time* pmtime) override;
310 virtual int read_usage(const DoutPrefixProvider *dpp, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries,
311 bool* is_truncated, RGWUsageIter& usage_iter,
312 std::map<rgw_user_bucket, rgw_usage_log_entry>& usage) override;
313 virtual int trim_usage(const DoutPrefixProvider *dpp, uint64_t start_epoch, uint64_t end_epoch) override;
314 virtual int remove_objs_from_index(const DoutPrefixProvider *dpp, std::list<rgw_obj_index_key>& objs_to_unlink) override;
315 virtual int check_index(const DoutPrefixProvider *dpp, std::map<RGWObjCategory, RGWStorageStats>& existing_stats, std::map<RGWObjCategory, RGWStorageStats>& calculated_stats) override;
316 virtual int rebuild_index(const DoutPrefixProvider *dpp) override;
317 virtual int set_tag_timeout(const DoutPrefixProvider *dpp, uint64_t timeout) override;
318 virtual int purge_instance(const DoutPrefixProvider* dpp) override;
319 virtual std::unique_ptr<Bucket> clone() override {
320 return std::make_unique<RadosBucket>(*this);
321 }
322 virtual std::unique_ptr<MultipartUpload> get_multipart_upload(
323 const std::string& oid,
324 std::optional<std::string> upload_id=std::nullopt,
325 ACLOwner owner={}, ceph::real_time mtime=real_clock::now()) override;
326 virtual int list_multiparts(const DoutPrefixProvider *dpp,
327 const std::string& prefix,
328 std::string& marker,
329 const std::string& delim,
330 const int& max_uploads,
331 std::vector<std::unique_ptr<MultipartUpload>>& uploads,
332 std::map<std::string, bool> *common_prefixes,
333 bool *is_truncated) override;
334 virtual int abort_multiparts(const DoutPrefixProvider* dpp,
335 CephContext* cct) override;
336
337 private:
338 int link(const DoutPrefixProvider* dpp, User* new_user, optional_yield y, bool update_entrypoint = true, RGWObjVersionTracker* objv = nullptr);
339 int unlink(const DoutPrefixProvider* dpp, User* new_user, optional_yield y, bool update_entrypoint = true);
340 friend class RadosUser;
341 };
342
343 class RadosZone : public Zone {
344 protected:
345 RadosStore* store;
346 public:
347 RadosZone(RadosStore* _store) : store(_store) {}
348 ~RadosZone() = default;
349
350 virtual const RGWZoneGroup& get_zonegroup() override;
351 virtual int get_zonegroup(const std::string& id, RGWZoneGroup& zonegroup) override;
352 virtual const RGWZoneParams& get_params() override;
353 virtual const rgw_zone_id& get_id() override;
354 virtual const RGWRealm& get_realm() override;
355 virtual const std::string& get_name() const override;
356 virtual bool is_writeable() override;
357 virtual bool get_redirect_endpoint(std::string* endpoint) override;
358 virtual bool has_zonegroup_api(const std::string& api) const override;
359 virtual const std::string& get_current_period_id() override;
360 };
361
362 class RadosStore : public Store {
363 private:
364 RGWRados* rados;
365 RGWUserCtl* user_ctl;
366 std::string luarocks_path;
367 RadosZone zone;
368
369 public:
370 RadosStore()
371 : rados(nullptr), zone(this) {
372 }
373 ~RadosStore() {
374 delete rados;
375 }
376
377 virtual const char* get_name() const override {
378 return "rados";
379 }
380
381 virtual std::unique_ptr<User> get_user(const rgw_user& u) override;
382 virtual std::string get_cluster_id(const DoutPrefixProvider* dpp, optional_yield y) override;
383 virtual int get_user_by_access_key(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y, std::unique_ptr<User>* user) override;
384 virtual int get_user_by_email(const DoutPrefixProvider* dpp, const std::string& email, optional_yield y, std::unique_ptr<User>* user) override;
385 virtual int get_user_by_swift(const DoutPrefixProvider* dpp, const std::string& user_str, optional_yield y, std::unique_ptr<User>* user) override;
386 virtual std::unique_ptr<Object> get_object(const rgw_obj_key& k) override;
387 virtual int get_bucket(const DoutPrefixProvider* dpp, User* u, const rgw_bucket& b, std::unique_ptr<Bucket>* bucket, optional_yield y) override;
388 virtual int get_bucket(User* u, const RGWBucketInfo& i, std::unique_ptr<Bucket>* bucket) override;
389 virtual int get_bucket(const DoutPrefixProvider* dpp, User* u, const std::string& tenant, const std::string&name, std::unique_ptr<Bucket>* bucket, optional_yield y) override;
390 virtual bool is_meta_master() override;
391 virtual int forward_request_to_master(const DoutPrefixProvider *dpp, User* user, obj_version* objv,
392 bufferlist& in_data, JSONParser* jp, req_info& info,
393 optional_yield y) override;
394 virtual Zone* get_zone() { return &zone; }
395 virtual std::string zone_unique_id(uint64_t unique_num) override;
396 virtual std::string zone_unique_trans_id(const uint64_t unique_num) override;
397 virtual int cluster_stat(RGWClusterStat& stats) override;
398 virtual std::unique_ptr<Lifecycle> get_lifecycle(void) override;
399 virtual std::unique_ptr<Completions> get_completions(void) override;
400
401 // op variant
402 virtual std::unique_ptr<Notification> get_notification(rgw::sal::Object* obj, rgw::sal::Object* src_obj, struct req_state* s, rgw::notify::EventType event_type, const std::string* object_name=nullptr) override;
403
404 // non-op variant (e.g., rgwlc)
405 virtual std::unique_ptr<Notification> get_notification(const DoutPrefixProvider* dpp, rgw::sal::Object* obj, rgw::sal::Object* src_obj, RGWObjectCtx* rctx, rgw::notify::EventType event_type, rgw::sal::Bucket* _bucket, std::string& _user_id, std::string& _user_tenant, std::string& _req_id, optional_yield y) override;
406 virtual RGWLC* get_rgwlc(void) override { return rados->get_lc(); }
407 virtual RGWCoroutinesManagerRegistry* get_cr_registry() override { return rados->get_cr_registry(); }
408
409 virtual int log_usage(const DoutPrefixProvider *dpp, std::map<rgw_user_bucket, RGWUsageBatch>& usage_info) override;
410 virtual int log_op(const DoutPrefixProvider *dpp, std::string& oid, bufferlist& bl) override;
411 virtual int register_to_service_map(const DoutPrefixProvider *dpp, const std::string& daemon_type,
412 const std::map<std::string, std::string>& meta) override;
413 virtual void get_quota(RGWQuotaInfo& bucket_quota, RGWQuotaInfo& user_quota) override;
414 virtual void get_ratelimit(RGWRateLimitInfo& bucket_ratelimit, RGWRateLimitInfo& user_ratelimit, RGWRateLimitInfo& anon_ratelimit) override;
415 virtual int set_buckets_enabled(const DoutPrefixProvider* dpp, std::vector<rgw_bucket>& buckets, bool enabled) override;
416 virtual uint64_t get_new_req_id() override { return rados->get_new_req_id(); }
417 virtual int get_sync_policy_handler(const DoutPrefixProvider* dpp,
418 std::optional<rgw_zone_id> zone,
419 std::optional<rgw_bucket> bucket,
420 RGWBucketSyncPolicyHandlerRef* phandler,
421 optional_yield y) override;
422 virtual RGWDataSyncStatusManager* get_data_sync_manager(const rgw_zone_id& source_zone) override;
423 virtual void wakeup_meta_sync_shards(std::set<int>& shard_ids) override { rados->wakeup_meta_sync_shards(shard_ids); }
424 virtual void wakeup_data_sync_shards(const DoutPrefixProvider *dpp, const rgw_zone_id& source_zone, std::map<int, std::set<std::string> >& shard_ids) override { rados->wakeup_data_sync_shards(dpp, source_zone, shard_ids); }
425 virtual int clear_usage(const DoutPrefixProvider *dpp) override { return rados->clear_usage(dpp); }
426 virtual int read_all_usage(const DoutPrefixProvider *dpp, uint64_t start_epoch, uint64_t end_epoch,
427 uint32_t max_entries, bool* is_truncated,
428 RGWUsageIter& usage_iter,
429 std::map<rgw_user_bucket, rgw_usage_log_entry>& usage) override;
430 virtual int trim_all_usage(const DoutPrefixProvider *dpp, uint64_t start_epoch, uint64_t end_epoch) override;
431 virtual int get_config_key_val(std::string name, bufferlist* bl) override;
432 virtual int meta_list_keys_init(const DoutPrefixProvider *dpp, const std::string& section, const std::string& marker, void** phandle) override;
433 virtual int meta_list_keys_next(const DoutPrefixProvider *dpp, void* handle, int max, std::list<std::string>& keys, bool* truncated) override;
434 virtual void meta_list_keys_complete(void* handle) override;
435 virtual std::string meta_get_marker(void* handle) override;
436 virtual int meta_remove(const DoutPrefixProvider* dpp, std::string& metadata_key, optional_yield y) override;
437 virtual const RGWSyncModuleInstanceRef& get_sync_module() { return rados->get_sync_module(); }
438 virtual std::string get_host_id() { return rados->host_id; }
439 virtual std::unique_ptr<LuaScriptManager> get_lua_script_manager() override;
440 virtual std::unique_ptr<RGWRole> get_role(std::string name,
441 std::string tenant,
442 std::string path="",
443 std::string trust_policy="",
444 std::string max_session_duration_str="",
445 std::multimap<std::string,std::string> tags={}) override;
446 virtual std::unique_ptr<RGWRole> get_role(std::string id) override;
447 virtual int get_roles(const DoutPrefixProvider *dpp,
448 optional_yield y,
449 const std::string& path_prefix,
450 const std::string& tenant,
451 std::vector<std::unique_ptr<RGWRole>>& roles) override;
452 virtual std::unique_ptr<RGWOIDCProvider> get_oidc_provider() override;
453 virtual int get_oidc_providers(const DoutPrefixProvider *dpp,
454 const std::string& tenant,
455 std::vector<std::unique_ptr<RGWOIDCProvider>>& providers) override;
456 virtual std::unique_ptr<Writer> get_append_writer(const DoutPrefixProvider *dpp,
457 optional_yield y,
458 std::unique_ptr<rgw::sal::Object> _head_obj,
459 const rgw_user& owner, RGWObjectCtx& obj_ctx,
460 const rgw_placement_rule *ptail_placement_rule,
461 const std::string& unique_tag,
462 uint64_t position,
463 uint64_t *cur_accounted_size) override;
464 virtual std::unique_ptr<Writer> get_atomic_writer(const DoutPrefixProvider *dpp,
465 optional_yield y,
466 std::unique_ptr<rgw::sal::Object> _head_obj,
467 const rgw_user& owner, RGWObjectCtx& obj_ctx,
468 const rgw_placement_rule *ptail_placement_rule,
469 uint64_t olh_epoch,
470 const std::string& unique_tag) override;
471
472 virtual void finalize(void) override;
473
474 virtual CephContext* ctx(void) override { return rados->ctx(); }
475
476 virtual const std::string& get_luarocks_path() const override {
477 return luarocks_path;
478 }
479
480 virtual void set_luarocks_path(const std::string& path) override {
481 luarocks_path = path;
482 }
483
484 /* Unique to RadosStore */
485 int get_obj_head_ioctx(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj,
486 librados::IoCtx* ioctx);
487 int delete_raw_obj(const DoutPrefixProvider *dpp, const rgw_raw_obj& obj);
488 int delete_raw_obj_aio(const DoutPrefixProvider *dpp, const rgw_raw_obj& obj, Completions* aio);
489 void get_raw_obj(const rgw_placement_rule& placement_rule, const rgw_obj& obj, rgw_raw_obj* raw_obj);
490 int get_raw_chunk_size(const DoutPrefixProvider* dpp, const rgw_raw_obj& obj, uint64_t* chunk_size);
491
492 void setRados(RGWRados * st) { rados = st; }
493 RGWRados* getRados(void) { return rados; }
494
495 RGWServices* svc() { return &rados->svc; }
496 const RGWServices* svc() const { return &rados->svc; }
497 RGWCtl* ctl() { return &rados->ctl; }
498 const RGWCtl* ctl() const { return &rados->ctl; }
499
500 void setUserCtl(RGWUserCtl *_ctl) { user_ctl = _ctl; }
501 };
502
503 class RadosMultipartPart : public MultipartPart {
504 protected:
505 RGWUploadPartInfo info;
506
507 public:
508 RadosMultipartPart() = default;
509 virtual ~RadosMultipartPart() = default;
510
511 virtual uint32_t get_num() { return info.num; }
512 virtual uint64_t get_size() { return info.accounted_size; }
513 virtual const std::string& get_etag() { return info.etag; }
514 virtual ceph::real_time& get_mtime() { return info.modified; }
515
516 /* For RadosStore code */
517 RGWObjManifest& get_manifest() { return info.manifest; }
518
519 friend class RadosMultipartUpload;
520 };
521
522 class RadosMultipartUpload : public MultipartUpload {
523 RadosStore* store;
524 RGWMPObj mp_obj;
525 ACLOwner owner;
526 ceph::real_time mtime;
527 rgw_placement_rule placement;
528 RGWObjManifest manifest;
529
530 public:
531 RadosMultipartUpload(RadosStore* _store, Bucket* _bucket, const std::string& oid,
532 std::optional<std::string> upload_id, ACLOwner owner,
533 ceph::real_time _mtime)
534 : MultipartUpload(_bucket), store(_store), mp_obj(oid, upload_id),
535 owner(owner), mtime(_mtime) {}
536 virtual ~RadosMultipartUpload() = default;
537
538 virtual const std::string& get_meta() const override { return mp_obj.get_meta(); }
539 virtual const std::string& get_key() const override { return mp_obj.get_key(); }
540 virtual const std::string& get_upload_id() const override { return mp_obj.get_upload_id(); }
541 virtual const ACLOwner& get_owner() const override { return owner; }
542 virtual ceph::real_time& get_mtime() override { return mtime; }
543 virtual std::unique_ptr<rgw::sal::Object> get_meta_obj() override;
544 virtual int init(const DoutPrefixProvider* dpp, optional_yield y, RGWObjectCtx* obj_ctx, ACLOwner& owner, rgw_placement_rule& dest_placement, rgw::sal::Attrs& attrs) override;
545 virtual int list_parts(const DoutPrefixProvider* dpp, CephContext* cct,
546 int num_parts, int marker,
547 int* next_marker, bool* truncated,
548 bool assume_unsorted = false) override;
549 virtual int abort(const DoutPrefixProvider* dpp, CephContext* cct,
550 RGWObjectCtx* obj_ctx) override;
551 virtual int complete(const DoutPrefixProvider* dpp,
552 optional_yield y, CephContext* cct,
553 std::map<int, std::string>& part_etags,
554 std::list<rgw_obj_index_key>& remove_objs,
555 uint64_t& accounted_size, bool& compressed,
556 RGWCompressionInfo& cs_info, off_t& ofs,
557 std::string& tag, ACLOwner& owner,
558 uint64_t olh_epoch,
559 rgw::sal::Object* target_obj,
560 RGWObjectCtx* obj_ctx) override;
561 virtual int get_info(const DoutPrefixProvider *dpp, optional_yield y, RGWObjectCtx* obj_ctx, rgw_placement_rule** rule, rgw::sal::Attrs* attrs = nullptr) override;
562 virtual std::unique_ptr<Writer> get_writer(const DoutPrefixProvider *dpp,
563 optional_yield y,
564 std::unique_ptr<rgw::sal::Object> _head_obj,
565 const rgw_user& owner, RGWObjectCtx& obj_ctx,
566 const rgw_placement_rule *ptail_placement_rule,
567 uint64_t part_num,
568 const std::string& part_num_str) override;
569 };
570
571 class MPRadosSerializer : public MPSerializer {
572 librados::IoCtx ioctx;
573 rados::cls::lock::Lock lock;
574 librados::ObjectWriteOperation op;
575
576 public:
577 MPRadosSerializer(const DoutPrefixProvider *dpp, RadosStore* store, RadosObject* obj, const std::string& lock_name);
578
579 virtual int try_lock(const DoutPrefixProvider *dpp, utime_t dur, optional_yield y) override;
580 virtual int unlock() override {
581 return lock.unlock(&ioctx, oid);
582 }
583 };
584
585 class LCRadosSerializer : public LCSerializer {
586 librados::IoCtx* ioctx;
587 rados::cls::lock::Lock lock;
588 const std::string oid;
589
590 public:
591 LCRadosSerializer(RadosStore* store, const std::string& oid, const std::string& lock_name, const std::string& cookie);
592
593 virtual int try_lock(const DoutPrefixProvider *dpp, utime_t dur, optional_yield y) override;
594 virtual int unlock() override {
595 return lock.unlock(ioctx, oid);
596 }
597 };
598
599 class RadosLifecycle : public Lifecycle {
600 RadosStore* store;
601
602 public:
603 RadosLifecycle(RadosStore* _st) : store(_st) {}
604
605 virtual int get_entry(const std::string& oid, const std::string& marker, LCEntry& entry) override;
606 virtual int get_next_entry(const std::string& oid, std::string& marker, LCEntry& entry) override;
607 virtual int set_entry(const std::string& oid, const LCEntry& entry) override;
608 virtual int list_entries(const std::string& oid, const std::string& marker,
609 uint32_t max_entries, std::vector<LCEntry>& entries) override;
610 virtual int rm_entry(const std::string& oid, const LCEntry& entry) override;
611 virtual int get_head(const std::string& oid, LCHead& head) override;
612 virtual int put_head(const std::string& oid, const LCHead& head) override;
613 virtual LCSerializer* get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) override;
614 };
615
616 class RadosNotification : public Notification {
617 RadosStore* store;
618 /* XXX it feels incorrect to me that rgw::notify::reservation_t is
619 * currently RADOS-specific; instead, I think notification types such as
620 * reservation_t should be generally visible, whereas the internal
621 * notification behavior should be made portable (e.g., notification
622 * to non-RADOS message sinks) */
623 rgw::notify::reservation_t res;
624
625 public:
626 RadosNotification(const DoutPrefixProvider* _dpp, RadosStore* _store, Object* _obj, Object* _src_obj, req_state* _s, rgw::notify::EventType _type, const std::string* object_name=nullptr) :
627 Notification(_obj, _src_obj, _type), store(_store), res(_dpp, _store, _s, _obj, _src_obj, object_name) { }
628
629 RadosNotification(const DoutPrefixProvider* _dpp, RadosStore* _store, Object* _obj, Object* _src_obj, RGWObjectCtx* rctx, rgw::notify::EventType _type, rgw::sal::Bucket* _bucket, std::string& _user_id, std::string& _user_tenant, std::string& _req_id, optional_yield y) :
630 Notification(_obj, _src_obj, _type), store(_store), res(_dpp, _store, rctx, _obj, _src_obj, _bucket, _user_id, _user_tenant, _req_id, y) {}
631
632 ~RadosNotification() = default;
633
634 rgw::notify::reservation_t& get_reservation(void) {
635 return res;
636 }
637
638 virtual int publish_reserve(const DoutPrefixProvider *dpp, RGWObjTags* obj_tags = nullptr) override;
639 virtual int publish_commit(const DoutPrefixProvider* dpp, uint64_t size,
640 const ceph::real_time& mtime, const std::string& etag, const std::string& version) override;
641 };
642
643 class RadosAtomicWriter : public Writer {
644 protected:
645 rgw::sal::RadosStore* store;
646 std::unique_ptr<Aio> aio;
647 rgw::putobj::AtomicObjectProcessor processor;
648
649 public:
650 RadosAtomicWriter(const DoutPrefixProvider *dpp,
651 optional_yield y,
652 std::unique_ptr<rgw::sal::Object> _head_obj,
653 RadosStore* _store, std::unique_ptr<Aio> _aio,
654 const rgw_user& owner, RGWObjectCtx& obj_ctx,
655 const rgw_placement_rule *ptail_placement_rule,
656 uint64_t olh_epoch,
657 const std::string& unique_tag) :
658 Writer(dpp, y),
659 store(_store),
660 aio(std::move(_aio)),
661 processor(&*aio, store,
662 ptail_placement_rule, owner, obj_ctx,
663 std::move(_head_obj), olh_epoch, unique_tag,
664 dpp, y)
665 {}
666 ~RadosAtomicWriter() = default;
667
668 // prepare to start processing object data
669 virtual int prepare(optional_yield y) override;
670
671 // Process a bufferlist
672 virtual int process(bufferlist&& data, uint64_t offset) override;
673
674 // complete the operation and make its result visible to clients
675 virtual int complete(size_t accounted_size, const std::string& etag,
676 ceph::real_time *mtime, ceph::real_time set_mtime,
677 std::map<std::string, bufferlist>& attrs,
678 ceph::real_time delete_at,
679 const char *if_match, const char *if_nomatch,
680 const std::string *user_data,
681 rgw_zone_set *zones_trace, bool *canceled,
682 optional_yield y) override;
683 };
684
685 class RadosAppendWriter : public Writer {
686 protected:
687 rgw::sal::RadosStore* store;
688 std::unique_ptr<Aio> aio;
689 rgw::putobj::AppendObjectProcessor processor;
690
691 public:
692 RadosAppendWriter(const DoutPrefixProvider *dpp,
693 optional_yield y,
694 std::unique_ptr<rgw::sal::Object> _head_obj,
695 RadosStore* _store, std::unique_ptr<Aio> _aio,
696 const rgw_user& owner, RGWObjectCtx& obj_ctx,
697 const rgw_placement_rule *ptail_placement_rule,
698 const std::string& unique_tag,
699 uint64_t position,
700 uint64_t *cur_accounted_size) :
701 Writer(dpp, y),
702 store(_store),
703 aio(std::move(_aio)),
704 processor(&*aio, store,
705 ptail_placement_rule, owner, obj_ctx,
706 std::move(_head_obj), unique_tag, position,
707 cur_accounted_size, dpp, y)
708 {}
709 ~RadosAppendWriter() = default;
710
711 // prepare to start processing object data
712 virtual int prepare(optional_yield y) override;
713
714 // Process a bufferlist
715 virtual int process(bufferlist&& data, uint64_t offset) override;
716
717 // complete the operation and make its result visible to clients
718 virtual int complete(size_t accounted_size, const std::string& etag,
719 ceph::real_time *mtime, ceph::real_time set_mtime,
720 std::map<std::string, bufferlist>& attrs,
721 ceph::real_time delete_at,
722 const char *if_match, const char *if_nomatch,
723 const std::string *user_data,
724 rgw_zone_set *zones_trace, bool *canceled,
725 optional_yield y) override;
726 };
727
728 class RadosMultipartWriter : public Writer {
729 protected:
730 rgw::sal::RadosStore* store;
731 std::unique_ptr<Aio> aio;
732 rgw::putobj::MultipartObjectProcessor processor;
733
734 public:
735 RadosMultipartWriter(const DoutPrefixProvider *dpp,
736 optional_yield y, MultipartUpload* upload,
737 std::unique_ptr<rgw::sal::Object> _head_obj,
738 RadosStore* _store, std::unique_ptr<Aio> _aio,
739 const rgw_user& owner, RGWObjectCtx& obj_ctx,
740 const rgw_placement_rule *ptail_placement_rule,
741 uint64_t part_num, const std::string& part_num_str) :
742 Writer(dpp, y),
743 store(_store),
744 aio(std::move(_aio)),
745 processor(&*aio, store,
746 ptail_placement_rule, owner, obj_ctx,
747 std::move(_head_obj), upload->get_upload_id(),
748 part_num, part_num_str, dpp, y)
749 {}
750 ~RadosMultipartWriter() = default;
751
752 // prepare to start processing object data
753 virtual int prepare(optional_yield y) override;
754
755 // Process a bufferlist
756 virtual int process(bufferlist&& data, uint64_t offset) override;
757
758 // complete the operation and make its result visible to clients
759 virtual int complete(size_t accounted_size, const std::string& etag,
760 ceph::real_time *mtime, ceph::real_time set_mtime,
761 std::map<std::string, bufferlist>& attrs,
762 ceph::real_time delete_at,
763 const char *if_match, const char *if_nomatch,
764 const std::string *user_data,
765 rgw_zone_set *zones_trace, bool *canceled,
766 optional_yield y) override;
767 };
768
769 class RadosLuaScriptManager : public LuaScriptManager {
770 RadosStore* store;
771 rgw_pool pool;
772
773 public:
774 RadosLuaScriptManager(RadosStore* _s) : store(_s)
775 {
776 pool = store->get_zone()->get_params().log_pool;
777 }
778 virtual ~RadosLuaScriptManager() = default;
779
780 virtual int get(const DoutPrefixProvider* dpp, optional_yield y, const std::string& key, std::string& script) override;
781 virtual int put(const DoutPrefixProvider* dpp, optional_yield y, const std::string& key, const std::string& script) override;
782 virtual int del(const DoutPrefixProvider* dpp, optional_yield y, const std::string& key) override;
783 };
784
785 class RadosOIDCProvider : public RGWOIDCProvider {
786 RadosStore* store;
787 public:
788 RadosOIDCProvider(RadosStore* _store) : store(_store) {}
789 ~RadosOIDCProvider() = default;
790
791 virtual int store_url(const DoutPrefixProvider *dpp, const std::string& url, bool exclusive, optional_yield y) override;
792 virtual int read_url(const DoutPrefixProvider *dpp, const std::string& url, const std::string& tenant) override;
793 virtual int delete_obj(const DoutPrefixProvider *dpp, optional_yield y) override;
794 void encode(bufferlist& bl) const {
795 RGWOIDCProvider::encode(bl);
796 }
797 void decode(bufferlist::const_iterator& bl) {
798 RGWOIDCProvider::decode(bl);
799 }
800 };
801
802 class RadosRole : public RGWRole {
803 RadosStore* store;
804 public:
805 RadosRole(RadosStore* _store, std::string name,
806 std::string tenant,
807 std::string path,
808 std::string trust_policy,
809 std::string max_session_duration,
810 std::multimap<std::string,std::string> tags) : RGWRole(name, tenant, path, trust_policy, max_session_duration, tags), store(_store) {}
811 RadosRole(RadosStore* _store, std::string id) : RGWRole(id), store(_store) {}
812 ~RadosRole() = default;
813
814 virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override;
815 virtual int store_name(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override;
816 virtual int store_path(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override;
817 virtual int read_id(const DoutPrefixProvider *dpp, const std::string& role_name, const std::string& tenant, std::string& role_id, optional_yield y) override;
818 virtual int read_name(const DoutPrefixProvider *dpp, optional_yield y) override;
819 virtual int read_info(const DoutPrefixProvider *dpp, optional_yield y) override;
820 virtual int create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override;
821 virtual int delete_obj(const DoutPrefixProvider *dpp, optional_yield y) override;
822 };
823
824 } } // namespace rgw::sal
825
826 WRITE_CLASS_ENCODER(rgw::sal::RadosOIDCProvider)