]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_sal_daos.h
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / rgw / rgw_sal_daos.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=2 sw=2 expandtab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * SAL implementation for the CORTX Daos backend
8 *
9 * Copyright (C) 2022 Seagate Technology LLC and/or its Affiliates
10 *
11 * This is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License version 2.1, as published by the Free Software
14 * Foundation. See file COPYING.
15 *
16 */
17
18 #pragma once
19
20 #include <daos.h>
21 #include <daos_s3.h>
22 #include <uuid/uuid.h>
23
24 #include <map>
25 #include <set>
26 #include <string>
27 #include <vector>
28
29 #include "rgw_multi.h"
30 #include "rgw_notify.h"
31 #include "rgw_oidc_provider.h"
32 #include "rgw_putobj_processor.h"
33 #include "rgw_rados.h"
34 #include "rgw_role.h"
35 #include "rgw_sal_store.h"
36
37 inline bool IsDebuggerAttached() {
38 #ifdef DEBUG
39 char buf[4096];
40
41 const int status_fd = ::open("/proc/self/status", O_RDONLY);
42 if (status_fd == -1) return false;
43
44 const ssize_t num_read = ::read(status_fd, buf, sizeof(buf) - 1);
45 ::close(status_fd);
46
47 if (num_read <= 0) return false;
48
49 buf[num_read] = '\0';
50 constexpr char tracerPidString[] = "TracerPid:";
51 const auto tracer_pid_ptr = ::strstr(buf, tracerPidString);
52 if (!tracer_pid_ptr) return false;
53
54 for (const char* characterPtr = tracer_pid_ptr + sizeof(tracerPidString) - 1;
55 characterPtr <= buf + num_read; ++characterPtr) {
56 if (::isspace(*characterPtr))
57 continue;
58 else
59 return ::isdigit(*characterPtr) != 0 && *characterPtr != '0';
60 }
61 #endif // DEBUG
62 return false;
63 }
64
65 inline void DebugBreak() {
66 #ifdef DEBUG
67 // only break into the debugger if the debugger is attached
68 if (IsDebuggerAttached())
69 raise(SIGINT); // breaks into GDB and stops, can be continued
70 #endif // DEBUG
71 }
72
73 inline int NotImplementedLog(const DoutPrefixProvider* ldpp,
74 const char* filename, int linenumber,
75 const char* functionname) {
76 if (ldpp)
77 ldpp_dout(ldpp, 20) << filename << "(" << linenumber << ") " << functionname
78 << ": Not implemented" << dendl;
79 return 0;
80 }
81
82 inline int NotImplementedGdbBreak(const DoutPrefixProvider* ldpp,
83 const char* filename, int linenumber,
84 const char* functionname) {
85 NotImplementedLog(ldpp, filename, linenumber, functionname);
86 DebugBreak();
87 return 0;
88 }
89
90 #define DAOS_NOT_IMPLEMENTED_GDB_BREAK(ldpp) \
91 NotImplementedGdbBreak(ldpp, __FILE__, __LINE__, __FUNCTION__)
92 #define DAOS_NOT_IMPLEMENTED_LOG(ldpp) \
93 NotImplementedLog(ldpp, __FILE__, __LINE__, __FUNCTION__)
94
95 namespace rgw::sal {
96
97 class DaosStore;
98 class DaosObject;
99
100 #ifdef DEBUG
101 // Prepends each log entry with the "filename(source_line) function_name". Makes
102 // it simple to
103 // associate log entries with the source that generated the log entry
104 #undef ldpp_dout
105 #define ldpp_dout(dpp, v) \
106 if (decltype(auto) pdpp = (dpp); \
107 pdpp) /* workaround -Wnonnull-compare for 'this' */ \
108 dout_impl(pdpp->get_cct(), ceph::dout::need_dynamic(pdpp->get_subsys()), v) \
109 pdpp->gen_prefix(*_dout) \
110 << __FILE__ << "(" << __LINE__ << ") " << __FUNCTION__ << " - "
111 #endif // DEBUG
112
113 struct DaosUserInfo {
114 RGWUserInfo info;
115 obj_version user_version;
116 rgw::sal::Attrs attrs;
117
118 void encode(bufferlist& bl) const {
119 ENCODE_START(3, 3, bl);
120 encode(info, bl);
121 encode(user_version, bl);
122 encode(attrs, bl);
123 ENCODE_FINISH(bl);
124 }
125
126 void decode(bufferlist::const_iterator& bl) {
127 DECODE_START(3, bl);
128 decode(info, bl);
129 decode(user_version, bl);
130 decode(attrs, bl);
131 DECODE_FINISH(bl);
132 }
133 };
134 WRITE_CLASS_ENCODER(DaosUserInfo);
135
136 class DaosNotification : public StoreNotification {
137 public:
138 DaosNotification(Object* _obj, Object* _src_obj, rgw::notify::EventType _type)
139 : StoreNotification(_obj, _src_obj, _type) {}
140 ~DaosNotification() = default;
141
142 virtual int publish_reserve(const DoutPrefixProvider* dpp,
143 RGWObjTags* obj_tags = nullptr) override {
144 return DAOS_NOT_IMPLEMENTED_LOG(dpp);
145 }
146 virtual int publish_commit(const DoutPrefixProvider* dpp, uint64_t size,
147 const ceph::real_time& mtime,
148 const std::string& etag,
149 const std::string& version) override {
150 return DAOS_NOT_IMPLEMENTED_LOG(dpp);
151 }
152 };
153
154 class DaosUser : public StoreUser {
155 private:
156 DaosStore* store;
157 std::vector<const char*> access_ids;
158
159 public:
160 DaosUser(DaosStore* _st, const rgw_user& _u) : StoreUser(_u), store(_st) {}
161 DaosUser(DaosStore* _st, const RGWUserInfo& _i) : StoreUser(_i), store(_st) {}
162 DaosUser(DaosStore* _st) : store(_st) {}
163 DaosUser(DaosUser& _o) = default;
164 DaosUser() {}
165
166 virtual std::unique_ptr<User> clone() override {
167 return std::make_unique<DaosUser>(*this);
168 }
169 int list_buckets(const DoutPrefixProvider* dpp, const std::string& marker,
170 const std::string& end_marker, uint64_t max, bool need_stats,
171 BucketList& buckets, optional_yield y) override;
172 virtual int create_bucket(
173 const DoutPrefixProvider* dpp, const rgw_bucket& b,
174 const std::string& zonegroup_id, rgw_placement_rule& placement_rule,
175 std::string& swift_ver_location, const RGWQuotaInfo* pquota_info,
176 const RGWAccessControlPolicy& policy, Attrs& attrs, RGWBucketInfo& info,
177 obj_version& ep_objv, bool exclusive, bool obj_lock_enabled,
178 bool* existed, req_info& req_info, std::unique_ptr<Bucket>* bucket,
179 optional_yield y) override;
180 virtual int read_attrs(const DoutPrefixProvider* dpp,
181 optional_yield y) override;
182 virtual int merge_and_store_attrs(const DoutPrefixProvider* dpp,
183 Attrs& new_attrs,
184 optional_yield y) override;
185 virtual int read_stats(const DoutPrefixProvider* dpp, optional_yield y,
186 RGWStorageStats* stats,
187 ceph::real_time* last_stats_sync = nullptr,
188 ceph::real_time* last_stats_update = nullptr) override;
189 virtual int read_stats_async(const DoutPrefixProvider* dpp,
190 RGWGetUserStats_CB* cb) override;
191 virtual int complete_flush_stats(const DoutPrefixProvider* dpp,
192 optional_yield y) override;
193 virtual int read_usage(
194 const DoutPrefixProvider* dpp, uint64_t start_epoch, uint64_t end_epoch,
195 uint32_t max_entries, bool* is_truncated, RGWUsageIter& usage_iter,
196 std::map<rgw_user_bucket, rgw_usage_log_entry>& usage) override;
197 virtual int trim_usage(const DoutPrefixProvider* dpp, uint64_t start_epoch,
198 uint64_t end_epoch) override;
199
200 virtual int load_user(const DoutPrefixProvider* dpp,
201 optional_yield y) override;
202 virtual int store_user(const DoutPrefixProvider* dpp, optional_yield y,
203 bool exclusive,
204 RGWUserInfo* old_info = nullptr) override;
205 virtual int remove_user(const DoutPrefixProvider* dpp,
206 optional_yield y) override;
207
208 /** Read user info without loading it */
209 int read_user(const DoutPrefixProvider* dpp, std::string name,
210 DaosUserInfo* duinfo);
211
212 std::unique_ptr<struct ds3_user_info> get_encoded_info(bufferlist& bl,
213 obj_version& obj_ver);
214
215 friend class DaosBucket;
216 };
217
218 // RGWBucketInfo and other information that are shown when listing a bucket is
219 // represented in struct DaosBucketInfo. The structure is encoded and stored
220 // as the value of the global bucket instance index.
221 // TODO: compare pros and cons of separating the bucket_attrs (ACLs, tag etc.)
222 // into a different index.
223 struct DaosBucketInfo {
224 RGWBucketInfo info;
225
226 obj_version bucket_version;
227 ceph::real_time mtime;
228
229 rgw::sal::Attrs bucket_attrs;
230
231 void encode(bufferlist& bl) const {
232 ENCODE_START(4, 4, bl);
233 encode(info, bl);
234 encode(bucket_version, bl);
235 encode(mtime, bl);
236 encode(bucket_attrs, bl); // rgw_cache.h example for a map
237 ENCODE_FINISH(bl);
238 }
239
240 void decode(bufferlist::const_iterator& bl) {
241 DECODE_START(4, bl);
242 decode(info, bl);
243 decode(bucket_version, bl);
244 decode(mtime, bl);
245 decode(bucket_attrs, bl);
246 DECODE_FINISH(bl);
247 }
248 };
249 WRITE_CLASS_ENCODER(DaosBucketInfo);
250
251 class DaosBucket : public StoreBucket {
252 private:
253 DaosStore* store;
254 RGWAccessControlPolicy acls;
255
256 public:
257 /** Container ds3b handle */
258 ds3_bucket_t* ds3b = nullptr;
259
260 DaosBucket(DaosStore* _st) : store(_st), acls() {}
261
262 DaosBucket(const DaosBucket& _daos_bucket)
263 : store(_daos_bucket.store), acls(), ds3b(nullptr) {
264 // TODO: deep copy all objects
265 }
266
267 DaosBucket(DaosStore* _st, User* _u) : StoreBucket(_u), store(_st), acls() {}
268
269 DaosBucket(DaosStore* _st, const rgw_bucket& _b)
270 : StoreBucket(_b), store(_st), acls() {}
271
272 DaosBucket(DaosStore* _st, const RGWBucketEnt& _e)
273 : StoreBucket(_e), store(_st), acls() {}
274
275 DaosBucket(DaosStore* _st, const RGWBucketInfo& _i)
276 : StoreBucket(_i), store(_st), acls() {}
277
278 DaosBucket(DaosStore* _st, const rgw_bucket& _b, User* _u)
279 : StoreBucket(_b, _u), store(_st), acls() {}
280
281 DaosBucket(DaosStore* _st, const RGWBucketEnt& _e, User* _u)
282 : StoreBucket(_e, _u), store(_st), acls() {}
283
284 DaosBucket(DaosStore* _st, const RGWBucketInfo& _i, User* _u)
285 : StoreBucket(_i, _u), store(_st), acls() {}
286
287 ~DaosBucket();
288
289 virtual std::unique_ptr<Object> get_object(const rgw_obj_key& k) override;
290 virtual int list(const DoutPrefixProvider* dpp, ListParams&, int,
291 ListResults&, optional_yield y) override;
292 virtual int remove_bucket(const DoutPrefixProvider* dpp, bool delete_children,
293 bool forward_to_master, req_info* req_info,
294 optional_yield y) override;
295 virtual int remove_bucket_bypass_gc(int concurrent_max,
296 bool keep_index_consistent,
297 optional_yield y,
298 const DoutPrefixProvider* dpp) override;
299 virtual RGWAccessControlPolicy& get_acl(void) override { return acls; }
300 virtual int set_acl(const DoutPrefixProvider* dpp,
301 RGWAccessControlPolicy& acl, optional_yield y) override;
302 virtual int load_bucket(const DoutPrefixProvider* dpp, optional_yield y,
303 bool get_stats = false) override;
304 virtual int read_stats(const DoutPrefixProvider* dpp,
305 const bucket_index_layout_generation& idx_layout,
306 int shard_id, std::string* bucket_ver,
307 std::string* master_ver,
308 std::map<RGWObjCategory, RGWStorageStats>& stats,
309 std::string* max_marker = nullptr,
310 bool* syncstopped = nullptr) override;
311 virtual int read_stats_async(const DoutPrefixProvider* dpp,
312 const bucket_index_layout_generation& idx_layout,
313 int shard_id,
314 RGWGetBucketStats_CB* ctx) override;
315 virtual int sync_user_stats(const DoutPrefixProvider* dpp,
316 optional_yield y) override;
317 virtual int update_container_stats(const DoutPrefixProvider* dpp) override;
318 virtual int check_bucket_shards(const DoutPrefixProvider* dpp) override;
319 virtual int chown(const DoutPrefixProvider* dpp, User& new_user,
320 optional_yield y) override;
321 virtual int put_info(const DoutPrefixProvider* dpp, bool exclusive,
322 ceph::real_time mtime) override;
323 virtual bool is_owner(User* user) override;
324 virtual int check_empty(const DoutPrefixProvider* dpp,
325 optional_yield y) override;
326 virtual int check_quota(const DoutPrefixProvider* dpp, RGWQuota& quota,
327 uint64_t obj_size, optional_yield y,
328 bool check_size_only = false) override;
329 virtual int merge_and_store_attrs(const DoutPrefixProvider* dpp, Attrs& attrs,
330 optional_yield y) override;
331 virtual int try_refresh_info(const DoutPrefixProvider* dpp,
332 ceph::real_time* pmtime) override;
333 virtual int read_usage(
334 const DoutPrefixProvider* dpp, uint64_t start_epoch, uint64_t end_epoch,
335 uint32_t max_entries, bool* is_truncated, RGWUsageIter& usage_iter,
336 std::map<rgw_user_bucket, rgw_usage_log_entry>& usage) override;
337 virtual int trim_usage(const DoutPrefixProvider* dpp, uint64_t start_epoch,
338 uint64_t end_epoch) override;
339 virtual int remove_objs_from_index(
340 const DoutPrefixProvider* dpp,
341 std::list<rgw_obj_index_key>& objs_to_unlink) override;
342 virtual int check_index(
343 const DoutPrefixProvider* dpp,
344 std::map<RGWObjCategory, RGWStorageStats>& existing_stats,
345 std::map<RGWObjCategory, RGWStorageStats>& calculated_stats) override;
346 virtual int rebuild_index(const DoutPrefixProvider* dpp) override;
347 virtual int set_tag_timeout(const DoutPrefixProvider* dpp,
348 uint64_t timeout) override;
349 virtual int purge_instance(const DoutPrefixProvider* dpp) override;
350 virtual std::unique_ptr<Bucket> clone() override {
351 return std::make_unique<DaosBucket>(*this);
352 }
353 virtual std::unique_ptr<MultipartUpload> get_multipart_upload(
354 const std::string& oid,
355 std::optional<std::string> upload_id = std::nullopt, ACLOwner owner = {},
356 ceph::real_time mtime = real_clock::now()) override;
357 virtual int list_multiparts(
358 const DoutPrefixProvider* dpp, const std::string& prefix,
359 std::string& marker, const std::string& delim, const int& max_uploads,
360 std::vector<std::unique_ptr<MultipartUpload>>& uploads,
361 std::map<std::string, bool>* common_prefixes,
362 bool* is_truncated) override;
363 virtual int abort_multiparts(const DoutPrefixProvider* dpp,
364 CephContext* cct) override;
365
366 int open(const DoutPrefixProvider* dpp);
367 int close(const DoutPrefixProvider* dpp);
368 bool is_open() { return ds3b != nullptr; }
369 std::unique_ptr<struct ds3_bucket_info> get_encoded_info(
370 bufferlist& bl, ceph::real_time mtime);
371
372 friend class DaosStore;
373 };
374
375 class DaosPlacementTier : public StorePlacementTier {
376 DaosStore* store;
377 RGWZoneGroupPlacementTier tier;
378
379 public:
380 DaosPlacementTier(DaosStore* _store, const RGWZoneGroupPlacementTier& _tier)
381 : store(_store), tier(_tier) {}
382 virtual ~DaosPlacementTier() = default;
383
384 virtual const std::string& get_tier_type() { return tier.tier_type; }
385 virtual const std::string& get_storage_class() { return tier.storage_class; }
386 virtual bool retain_head_object() { return tier.retain_head_object; }
387 RGWZoneGroupPlacementTier& get_rt() { return tier; }
388 };
389
390 class DaosZoneGroup : public StoreZoneGroup {
391 DaosStore* store;
392 const RGWZoneGroup group;
393 std::string empty;
394
395 public:
396 DaosZoneGroup(DaosStore* _store) : store(_store), group() {}
397 DaosZoneGroup(DaosStore* _store, const RGWZoneGroup& _group)
398 : store(_store), group(_group) {}
399 virtual ~DaosZoneGroup() = default;
400
401 virtual const std::string& get_id() const override { return group.get_id(); };
402 virtual const std::string& get_name() const override {
403 return group.get_name();
404 };
405 virtual int equals(const std::string& other_zonegroup) const override {
406 return group.equals(other_zonegroup);
407 };
408 /** Get the endpoint from zonegroup, or from master zone if not set */
409 virtual const std::string& get_endpoint() const override;
410 virtual bool placement_target_exists(std::string& target) const override;
411 virtual bool is_master_zonegroup() const override {
412 return group.is_master_zonegroup();
413 };
414 virtual const std::string& get_api_name() const override {
415 return group.api_name;
416 };
417 virtual int get_placement_target_names(
418 std::set<std::string>& names) const override;
419 virtual const std::string& get_default_placement_name() const override {
420 return group.default_placement.name;
421 };
422 virtual int get_hostnames(std::list<std::string>& names) const override {
423 names = group.hostnames;
424 return 0;
425 };
426 virtual int get_s3website_hostnames(
427 std::list<std::string>& names) const override {
428 names = group.hostnames_s3website;
429 return 0;
430 };
431 virtual int get_zone_count() const override { return group.zones.size(); }
432 virtual int get_placement_tier(const rgw_placement_rule& rule,
433 std::unique_ptr<PlacementTier>* tier);
434 bool supports(std::string_view feature) const override {
435 return group.supports(feature);
436 }
437 virtual std::unique_ptr<ZoneGroup> clone() override {
438 return std::make_unique<DaosZoneGroup>(store, group);
439 }
440 const RGWZoneGroup& get_group() { return group; }
441 };
442
443 class DaosZone : public StoreZone {
444 protected:
445 DaosStore* store;
446 RGWRealm* realm{nullptr};
447 DaosZoneGroup zonegroup;
448 RGWZone* zone_public_config{
449 nullptr}; /* external zone params, e.g., entrypoints, log flags, etc. */
450 RGWZoneParams* zone_params{
451 nullptr}; /* internal zone params, e.g., rados pools */
452 RGWPeriod* current_period{nullptr};
453 rgw_zone_id cur_zone_id;
454
455 public:
456 DaosZone(DaosStore* _store) : store(_store), zonegroup(_store) {
457 realm = new RGWRealm();
458 zone_public_config = new RGWZone();
459 zone_params = new RGWZoneParams();
460 current_period = new RGWPeriod();
461 cur_zone_id = rgw_zone_id(zone_params->get_id());
462
463 // XXX: only default and STANDARD supported for now
464 RGWZonePlacementInfo info;
465 RGWZoneStorageClasses sc;
466 sc.set_storage_class("STANDARD", nullptr, nullptr);
467 info.storage_classes = sc;
468 zone_params->placement_pools["default"] = info;
469 }
470 DaosZone(DaosStore* _store, DaosZoneGroup _zg)
471 : store(_store), zonegroup(_zg) {
472 realm = new RGWRealm();
473 zone_public_config = new RGWZone();
474 zone_params = new RGWZoneParams();
475 current_period = new RGWPeriod();
476 cur_zone_id = rgw_zone_id(zone_params->get_id());
477
478 // XXX: only default and STANDARD supported for now
479 RGWZonePlacementInfo info;
480 RGWZoneStorageClasses sc;
481 sc.set_storage_class("STANDARD", nullptr, nullptr);
482 info.storage_classes = sc;
483 zone_params->placement_pools["default"] = info;
484 }
485 ~DaosZone() = default;
486
487 virtual std::unique_ptr<Zone> clone() override {
488 return std::make_unique<DaosZone>(store);
489 }
490 virtual ZoneGroup& get_zonegroup() override;
491 virtual int get_zonegroup(const std::string& id,
492 std::unique_ptr<ZoneGroup>* zonegroup) override;
493 virtual const rgw_zone_id& get_id() override;
494 virtual const std::string& get_name() const override;
495 virtual bool is_writeable() override;
496 virtual bool get_redirect_endpoint(std::string* endpoint) override;
497 virtual bool has_zonegroup_api(const std::string& api) const override;
498 virtual const std::string& get_current_period_id() override;
499 virtual const RGWAccessKey& get_system_key() {
500 return zone_params->system_key;
501 }
502 virtual const std::string& get_realm_name() { return realm->get_name(); }
503 virtual const std::string& get_realm_id() { return realm->get_id(); }
504 virtual const std::string_view get_tier_type() { return "rgw"; }
505
506 friend class DaosStore;
507 };
508
509 class DaosLuaManager : public StoreLuaManager {
510 DaosStore* store;
511
512 public:
513 DaosLuaManager(DaosStore* _s) : store(_s) {}
514 virtual ~DaosLuaManager() = default;
515
516 virtual int get_script(const DoutPrefixProvider* dpp, optional_yield y,
517 const std::string& key, std::string& script) override {
518 DAOS_NOT_IMPLEMENTED_LOG(dpp);
519 return -ENOENT;
520 };
521
522 virtual int put_script(const DoutPrefixProvider* dpp, optional_yield y,
523 const std::string& key,
524 const std::string& script) override {
525 DAOS_NOT_IMPLEMENTED_LOG(dpp);
526 return -ENOENT;
527 };
528
529 virtual int del_script(const DoutPrefixProvider* dpp, optional_yield y,
530 const std::string& key) override {
531 DAOS_NOT_IMPLEMENTED_LOG(dpp);
532 return -ENOENT;
533 };
534
535 virtual int add_package(const DoutPrefixProvider* dpp, optional_yield y,
536 const std::string& package_name) override {
537 DAOS_NOT_IMPLEMENTED_LOG(dpp);
538 return -ENOENT;
539 };
540
541 virtual int remove_package(const DoutPrefixProvider* dpp, optional_yield y,
542 const std::string& package_name) override {
543 DAOS_NOT_IMPLEMENTED_LOG(dpp);
544 return -ENOENT;
545 };
546
547 virtual int list_packages(const DoutPrefixProvider* dpp, optional_yield y,
548 rgw::lua::packages_t& packages) override {
549 DAOS_NOT_IMPLEMENTED_LOG(dpp);
550 return -ENOENT;
551 };
552 };
553
554 class DaosObject : public StoreObject {
555 private:
556 DaosStore* store;
557 RGWAccessControlPolicy acls;
558
559 public:
560 struct DaosReadOp : public StoreReadOp {
561 private:
562 DaosObject* source;
563
564 public:
565 DaosReadOp(DaosObject* _source);
566
567 virtual int prepare(optional_yield y,
568 const DoutPrefixProvider* dpp) override;
569
570 /*
571 * Both `read` and `iterate` read up through index `end`
572 * *inclusive*. The number of bytes that could be returned is
573 * `end - ofs + 1`.
574 */
575 virtual int read(int64_t off, int64_t end, bufferlist& bl, optional_yield y,
576 const DoutPrefixProvider* dpp) override;
577 virtual int iterate(const DoutPrefixProvider* dpp, int64_t off, int64_t end,
578 RGWGetDataCB* cb, optional_yield y) override;
579
580 virtual int get_attr(const DoutPrefixProvider* dpp, const char* name,
581 bufferlist& dest, optional_yield y) override;
582 };
583
584 struct DaosDeleteOp : public StoreDeleteOp {
585 private:
586 DaosObject* source;
587
588 public:
589 DaosDeleteOp(DaosObject* _source);
590
591 virtual int delete_obj(const DoutPrefixProvider* dpp,
592 optional_yield y) override;
593 };
594
595 ds3_obj_t* ds3o = nullptr;
596
597 DaosObject() = default;
598
599 DaosObject(DaosStore* _st, const rgw_obj_key& _k)
600 : StoreObject(_k), store(_st), acls() {}
601 DaosObject(DaosStore* _st, const rgw_obj_key& _k, Bucket* _b)
602 : StoreObject(_k, _b), store(_st), acls() {}
603
604 DaosObject(DaosObject& _o) = default;
605
606 virtual ~DaosObject();
607
608 virtual int delete_object(const DoutPrefixProvider* dpp, optional_yield y,
609 bool prevent_versioning = false) override;
610 virtual int delete_obj_aio(const DoutPrefixProvider* dpp, RGWObjState* astate,
611 Completions* aio, bool keep_index_consistent,
612 optional_yield y) override;
613 virtual int copy_object(
614 User* user, req_info* info, const rgw_zone_id& source_zone,
615 rgw::sal::Object* dest_object, rgw::sal::Bucket* dest_bucket,
616 rgw::sal::Bucket* src_bucket, const rgw_placement_rule& dest_placement,
617 ceph::real_time* src_mtime, ceph::real_time* mtime,
618 const ceph::real_time* mod_ptr, const ceph::real_time* unmod_ptr,
619 bool high_precision_time, const char* if_match, const char* if_nomatch,
620 AttrsMod attrs_mod, bool copy_if_newer, Attrs& attrs,
621 RGWObjCategory category, uint64_t olh_epoch,
622 boost::optional<ceph::real_time> delete_at, std::string* version_id,
623 std::string* tag, std::string* etag, void (*progress_cb)(off_t, void*),
624 void* progress_data, const DoutPrefixProvider* dpp,
625 optional_yield y) override;
626 virtual RGWAccessControlPolicy& get_acl(void) override { return acls; }
627 virtual int set_acl(const RGWAccessControlPolicy& acl) override {
628 acls = acl;
629 return 0;
630 }
631
632 virtual int get_obj_state(const DoutPrefixProvider* dpp, RGWObjState** state,
633 optional_yield y, bool follow_olh = true) override;
634 virtual int set_obj_attrs(const DoutPrefixProvider* dpp, Attrs* setattrs,
635 Attrs* delattrs, optional_yield y) override;
636 virtual int get_obj_attrs(optional_yield y, const DoutPrefixProvider* dpp,
637 rgw_obj* target_obj = NULL) override;
638 virtual int modify_obj_attrs(const char* attr_name, bufferlist& attr_val,
639 optional_yield y,
640 const DoutPrefixProvider* dpp) override;
641 virtual int delete_obj_attrs(const DoutPrefixProvider* dpp,
642 const char* attr_name,
643 optional_yield y) override;
644 virtual bool is_expired() override;
645 virtual void gen_rand_obj_instance_name() override;
646 virtual std::unique_ptr<Object> clone() override {
647 return std::make_unique<DaosObject>(*this);
648 }
649 virtual std::unique_ptr<MPSerializer> get_serializer(
650 const DoutPrefixProvider* dpp, const std::string& lock_name) override;
651 virtual int transition(Bucket* bucket,
652 const rgw_placement_rule& placement_rule,
653 const real_time& mtime, uint64_t olh_epoch,
654 const DoutPrefixProvider* dpp,
655 optional_yield y) override;
656 virtual int transition_to_cloud(Bucket* bucket, rgw::sal::PlacementTier* tier,
657 rgw_bucket_dir_entry& o,
658 std::set<std::string>& cloud_targets,
659 CephContext* cct, bool update_object,
660 const DoutPrefixProvider* dpp,
661 optional_yield y) override;
662 virtual bool placement_rules_match(rgw_placement_rule& r1,
663 rgw_placement_rule& r2) override;
664 virtual int dump_obj_layout(const DoutPrefixProvider* dpp, optional_yield y,
665 Formatter* f) override;
666
667 /* Swift versioning */
668 virtual int swift_versioning_restore(bool& restored,
669 const DoutPrefixProvider* dpp) override;
670 virtual int swift_versioning_copy(const DoutPrefixProvider* dpp,
671 optional_yield y) override;
672
673 /* OPs */
674 virtual std::unique_ptr<ReadOp> get_read_op() override;
675 virtual std::unique_ptr<DeleteOp> get_delete_op() override;
676
677 /* OMAP */
678 virtual int omap_get_vals(const DoutPrefixProvider* dpp,
679 const std::string& marker, uint64_t count,
680 std::map<std::string, bufferlist>* m, bool* pmore,
681 optional_yield y) override;
682 virtual int omap_get_all(const DoutPrefixProvider* dpp,
683 std::map<std::string, bufferlist>* m,
684 optional_yield y) override;
685 virtual int omap_get_vals_by_keys(const DoutPrefixProvider* dpp,
686 const std::string& oid,
687 const std::set<std::string>& keys,
688 Attrs* vals) override;
689 virtual int omap_set_val_by_key(const DoutPrefixProvider* dpp,
690 const std::string& key, bufferlist& val,
691 bool must_exist, optional_yield y) override;
692 virtual int chown(User& new_user, const DoutPrefixProvider* dpp,
693 optional_yield y) override;
694
695 bool is_open() { return ds3o != nullptr; };
696 // Only lookup the object, do not create
697 int lookup(const DoutPrefixProvider* dpp);
698 // Create the object, truncate if exists
699 int create(const DoutPrefixProvider* dpp);
700 // Release the daos resources
701 int close(const DoutPrefixProvider* dpp);
702 // Write to object starting from offset
703 int write(const DoutPrefixProvider* dpp, bufferlist&& data, uint64_t offset);
704 // Read size bytes from object starting from offset
705 int read(const DoutPrefixProvider* dpp, bufferlist& data, uint64_t offset,
706 uint64_t& size);
707 // Get the object's dirent and attrs
708 int get_dir_entry_attrs(const DoutPrefixProvider* dpp,
709 rgw_bucket_dir_entry* ent, Attrs* getattrs = nullptr);
710 // Set the object's dirent and attrs
711 int set_dir_entry_attrs(const DoutPrefixProvider* dpp,
712 rgw_bucket_dir_entry* ent, Attrs* setattrs = nullptr);
713 // Marks this DAOS object as being the latest version and unmarks all other
714 // versions as latest
715 int mark_as_latest(const DoutPrefixProvider* dpp, ceph::real_time set_mtime);
716 // get_bucket casted as DaosBucket*
717 DaosBucket* get_daos_bucket() {
718 return static_cast<DaosBucket*>(get_bucket());
719 }
720 };
721
722 // A placeholder locking class for multipart upload.
723 class MPDaosSerializer : public StoreMPSerializer {
724 public:
725 MPDaosSerializer(const DoutPrefixProvider* dpp, DaosStore* store,
726 DaosObject* obj, const std::string& lock_name) {}
727
728 virtual int try_lock(const DoutPrefixProvider* dpp, utime_t dur,
729 optional_yield y) override {
730 return DAOS_NOT_IMPLEMENTED_LOG(dpp);
731 }
732 virtual int unlock() override { return DAOS_NOT_IMPLEMENTED_LOG(nullptr); }
733 };
734
735 class DaosAtomicWriter : public StoreWriter {
736 protected:
737 rgw::sal::DaosStore* store;
738 const rgw_user& owner;
739 const rgw_placement_rule* ptail_placement_rule;
740 uint64_t olh_epoch;
741 const std::string& unique_tag;
742 DaosObject obj;
743 uint64_t total_data_size = 0; // for total data being uploaded
744
745 public:
746 DaosAtomicWriter(const DoutPrefixProvider* dpp, optional_yield y,
747 rgw::sal::Object* obj,
748 DaosStore* _store, const rgw_user& _owner,
749 const rgw_placement_rule* _ptail_placement_rule,
750 uint64_t _olh_epoch, const std::string& _unique_tag);
751 ~DaosAtomicWriter() = default;
752
753 // prepare to start processing object data
754 virtual int prepare(optional_yield y) override;
755
756 // Process a bufferlist
757 virtual int process(bufferlist&& data, uint64_t offset) override;
758
759 // complete the operation and make its result visible to clients
760 virtual int complete(size_t accounted_size, const std::string& etag,
761 ceph::real_time* mtime, ceph::real_time set_mtime,
762 std::map<std::string, bufferlist>& attrs,
763 ceph::real_time delete_at, const char* if_match,
764 const char* if_nomatch, const std::string* user_data,
765 rgw_zone_set* zones_trace, bool* canceled,
766 optional_yield y) override;
767 };
768
769 class DaosMultipartWriter : public StoreWriter {
770 protected:
771 rgw::sal::DaosStore* store;
772 MultipartUpload* upload;
773 std::string upload_id;
774
775 // Part parameters.
776 const uint64_t part_num;
777 const std::string part_num_str;
778 uint64_t actual_part_size = 0;
779
780 ds3_part_t* ds3p = nullptr;
781 bool is_open() { return ds3p != nullptr; };
782
783 public:
784 DaosMultipartWriter(const DoutPrefixProvider* dpp, optional_yield y,
785 MultipartUpload* _upload,
786 rgw::sal::Object* obj,
787 DaosStore* _store, const rgw_user& owner,
788 const rgw_placement_rule* ptail_placement_rule,
789 uint64_t _part_num, const std::string& part_num_str)
790 : StoreWriter(dpp, y),
791 store(_store),
792 upload(_upload),
793 upload_id(_upload->get_upload_id()),
794 part_num(_part_num),
795 part_num_str(part_num_str) {}
796 virtual ~DaosMultipartWriter();
797
798 // prepare to start processing object data
799 virtual int prepare(optional_yield y) override;
800
801 // Process a bufferlist
802 virtual int process(bufferlist&& data, uint64_t offset) override;
803
804 // complete the operation and make its result visible to clients
805 virtual int complete(size_t accounted_size, const std::string& etag,
806 ceph::real_time* mtime, ceph::real_time set_mtime,
807 std::map<std::string, bufferlist>& attrs,
808 ceph::real_time delete_at, const char* if_match,
809 const char* if_nomatch, const std::string* user_data,
810 rgw_zone_set* zones_trace, bool* canceled,
811 optional_yield y) override;
812
813 const std::string& get_bucket_name();
814 };
815
816 class DaosMultipartPart : public StoreMultipartPart {
817 protected:
818 RGWUploadPartInfo info;
819
820 public:
821 DaosMultipartPart() = default;
822 virtual ~DaosMultipartPart() = default;
823
824 virtual uint32_t get_num() { return info.num; }
825 virtual uint64_t get_size() { return info.accounted_size; }
826 virtual const std::string& get_etag() { return info.etag; }
827 virtual ceph::real_time& get_mtime() { return info.modified; }
828
829 friend class DaosMultipartUpload;
830 };
831
832 class DaosMultipartUpload : public StoreMultipartUpload {
833 DaosStore* store;
834 RGWMPObj mp_obj;
835 ACLOwner owner;
836 ceph::real_time mtime;
837 rgw_placement_rule placement;
838 RGWObjManifest manifest;
839
840 public:
841 DaosMultipartUpload(DaosStore* _store, Bucket* _bucket,
842 const std::string& oid,
843 std::optional<std::string> upload_id, ACLOwner _owner,
844 ceph::real_time _mtime)
845 : StoreMultipartUpload(_bucket),
846 store(_store),
847 mp_obj(oid, upload_id),
848 owner(_owner),
849 mtime(_mtime) {}
850 virtual ~DaosMultipartUpload() = default;
851
852 virtual const std::string& get_meta() const { return mp_obj.get_meta(); }
853 virtual const std::string& get_key() const { return mp_obj.get_key(); }
854 virtual const std::string& get_upload_id() const {
855 return mp_obj.get_upload_id();
856 }
857 virtual const ACLOwner& get_owner() const override { return owner; }
858 virtual ceph::real_time& get_mtime() { return mtime; }
859 virtual std::unique_ptr<rgw::sal::Object> get_meta_obj() override;
860 virtual int init(const DoutPrefixProvider* dpp, optional_yield y,
861 ACLOwner& owner, rgw_placement_rule& dest_placement,
862 rgw::sal::Attrs& attrs) override;
863 virtual int list_parts(const DoutPrefixProvider* dpp, CephContext* cct,
864 int num_parts, int marker, int* next_marker,
865 bool* truncated,
866 bool assume_unsorted = false) override;
867 virtual int abort(const DoutPrefixProvider* dpp, CephContext* cct) override;
868 virtual int complete(const DoutPrefixProvider* dpp, optional_yield y,
869 CephContext* cct, std::map<int, std::string>& part_etags,
870 std::list<rgw_obj_index_key>& remove_objs,
871 uint64_t& accounted_size, bool& compressed,
872 RGWCompressionInfo& cs_info, off_t& off,
873 std::string& tag, ACLOwner& owner, uint64_t olh_epoch,
874 rgw::sal::Object* target_obj) override;
875 virtual int get_info(const DoutPrefixProvider* dpp, optional_yield y,
876 rgw_placement_rule** rule,
877 rgw::sal::Attrs* attrs = nullptr) override;
878 virtual std::unique_ptr<Writer> get_writer(
879 const DoutPrefixProvider* dpp, optional_yield y,
880 rgw::sal::Object* obj, const rgw_user& owner,
881 const rgw_placement_rule* ptail_placement_rule, uint64_t part_num,
882 const std::string& part_num_str) override;
883 const std::string& get_bucket_name() { return bucket->get_name(); }
884 };
885
886 class DaosStore : public StoreDriver {
887 private:
888 DaosZone zone;
889 RGWSyncModuleInstanceRef sync_module;
890
891 public:
892 ds3_t* ds3 = nullptr;
893
894 CephContext* cctx;
895
896 DaosStore(CephContext* c) : zone(this), cctx(c) {}
897 ~DaosStore() = default;
898
899 virtual const std::string get_name() const override { return "daos"; }
900
901 virtual std::unique_ptr<User> get_user(const rgw_user& u) override;
902 virtual std::string get_cluster_id(const DoutPrefixProvider* dpp,
903 optional_yield y) override;
904 virtual int get_user_by_access_key(const DoutPrefixProvider* dpp,
905 const std::string& key, optional_yield y,
906 std::unique_ptr<User>* user) override;
907 virtual int get_user_by_email(const DoutPrefixProvider* dpp,
908 const std::string& email, optional_yield y,
909 std::unique_ptr<User>* user) override;
910 virtual int get_user_by_swift(const DoutPrefixProvider* dpp,
911 const std::string& user_str, optional_yield y,
912 std::unique_ptr<User>* user) override;
913 virtual std::unique_ptr<Object> get_object(const rgw_obj_key& k) override;
914 virtual int get_bucket(const DoutPrefixProvider* dpp, User* u,
915 const rgw_bucket& b, std::unique_ptr<Bucket>* bucket,
916 optional_yield y) override;
917 virtual int get_bucket(User* u, const RGWBucketInfo& i,
918 std::unique_ptr<Bucket>* bucket) override;
919 virtual int get_bucket(const DoutPrefixProvider* dpp, User* u,
920 const std::string& tenant, const std::string& name,
921 std::unique_ptr<Bucket>* bucket,
922 optional_yield y) override;
923 virtual bool is_meta_master() override;
924 virtual int forward_request_to_master(const DoutPrefixProvider* dpp,
925 User* user, obj_version* objv,
926 bufferlist& in_data, JSONParser* jp,
927 req_info& info,
928 optional_yield y) override;
929 virtual int forward_iam_request_to_master(
930 const DoutPrefixProvider* dpp, const RGWAccessKey& key, obj_version* objv,
931 bufferlist& in_data, RGWXMLDecoder::XMLParser* parser, req_info& info,
932 optional_yield y) override;
933 virtual Zone* get_zone() { return &zone; }
934 virtual std::string zone_unique_id(uint64_t unique_num) override;
935 virtual std::string zone_unique_trans_id(const uint64_t unique_num) override;
936 virtual int cluster_stat(RGWClusterStat& stats) override;
937 virtual std::unique_ptr<Lifecycle> get_lifecycle(void) override;
938 virtual std::unique_ptr<Completions> get_completions(void) override;
939 virtual std::unique_ptr<Notification> get_notification(
940 rgw::sal::Object* obj, rgw::sal::Object* src_obj, struct req_state* s,
941 rgw::notify::EventType event_type, optional_yield y,
942 const std::string* object_name = nullptr) override;
943 virtual std::unique_ptr<Notification> get_notification(
944 const DoutPrefixProvider* dpp, rgw::sal::Object* obj,
945 rgw::sal::Object* src_obj, rgw::notify::EventType event_type,
946 rgw::sal::Bucket* _bucket, std::string& _user_id,
947 std::string& _user_tenant, std::string& _req_id,
948 optional_yield y) override;
949 virtual RGWLC* get_rgwlc(void) override { return NULL; }
950 virtual RGWCoroutinesManagerRegistry* get_cr_registry() override {
951 return NULL;
952 }
953
954 virtual int log_usage(
955 const DoutPrefixProvider* dpp,
956 std::map<rgw_user_bucket, RGWUsageBatch>& usage_info) override;
957 virtual int log_op(const DoutPrefixProvider* dpp, std::string& oid,
958 bufferlist& bl) override;
959 virtual int register_to_service_map(
960 const DoutPrefixProvider* dpp, const std::string& daemon_type,
961 const std::map<std::string, std::string>& meta) override;
962 virtual void get_quota(RGWQuota& quota) override;
963 virtual void get_ratelimit(RGWRateLimitInfo& bucket_ratelimit,
964 RGWRateLimitInfo& user_ratelimit,
965 RGWRateLimitInfo& anon_ratelimit) override;
966 virtual int set_buckets_enabled(const DoutPrefixProvider* dpp,
967 std::vector<rgw_bucket>& buckets,
968 bool enabled) override;
969 virtual uint64_t get_new_req_id() override {
970 return DAOS_NOT_IMPLEMENTED_LOG(nullptr);
971 }
972 virtual int get_sync_policy_handler(const DoutPrefixProvider* dpp,
973 std::optional<rgw_zone_id> zone,
974 std::optional<rgw_bucket> bucket,
975 RGWBucketSyncPolicyHandlerRef* phandler,
976 optional_yield y) override;
977 virtual RGWDataSyncStatusManager* get_data_sync_manager(
978 const rgw_zone_id& source_zone) override;
979 virtual void wakeup_meta_sync_shards(std::set<int>& shard_ids) override {
980 return;
981 }
982 virtual void wakeup_data_sync_shards(
983 const DoutPrefixProvider* dpp, const rgw_zone_id& source_zone,
984 boost::container::flat_map<
985 int, boost::container::flat_set<rgw_data_notify_entry>>& shard_ids)
986 override {
987 return;
988 }
989 virtual int clear_usage(const DoutPrefixProvider* dpp) override {
990 return DAOS_NOT_IMPLEMENTED_LOG(dpp);
991 }
992 virtual int read_all_usage(
993 const DoutPrefixProvider* dpp, uint64_t start_epoch, uint64_t end_epoch,
994 uint32_t max_entries, bool* is_truncated, RGWUsageIter& usage_iter,
995 std::map<rgw_user_bucket, rgw_usage_log_entry>& usage) override;
996 virtual int trim_all_usage(const DoutPrefixProvider* dpp,
997 uint64_t start_epoch, uint64_t end_epoch) override;
998 virtual int get_config_key_val(std::string name, bufferlist* bl) override;
999 virtual int meta_list_keys_init(const DoutPrefixProvider* dpp,
1000 const std::string& section,
1001 const std::string& marker,
1002 void** phandle) override;
1003 virtual int meta_list_keys_next(const DoutPrefixProvider* dpp, void* handle,
1004 int max, std::list<std::string>& keys,
1005 bool* truncated) override;
1006 virtual void meta_list_keys_complete(void* handle) override;
1007 virtual std::string meta_get_marker(void* handle) override;
1008 virtual int meta_remove(const DoutPrefixProvider* dpp,
1009 std::string& metadata_key, optional_yield y) override;
1010
1011 virtual const RGWSyncModuleInstanceRef& get_sync_module() {
1012 return sync_module;
1013 }
1014 virtual std::string get_host_id() { return ""; }
1015
1016 virtual std::unique_ptr<LuaManager> get_lua_manager() override;
1017 virtual std::unique_ptr<RGWRole> get_role(
1018 std::string name, std::string tenant, std::string path = "",
1019 std::string trust_policy = "", std::string max_session_duration_str = "",
1020 std::multimap<std::string, std::string> tags = {}) override;
1021 virtual std::unique_ptr<RGWRole> get_role(const RGWRoleInfo& info) override;
1022 virtual std::unique_ptr<RGWRole> get_role(std::string id) override;
1023 virtual int get_roles(const DoutPrefixProvider* dpp, optional_yield y,
1024 const std::string& path_prefix,
1025 const std::string& tenant,
1026 std::vector<std::unique_ptr<RGWRole>>& roles) override;
1027 virtual std::unique_ptr<RGWOIDCProvider> get_oidc_provider() override;
1028 virtual int get_oidc_providers(
1029 const DoutPrefixProvider* dpp, const std::string& tenant,
1030 std::vector<std::unique_ptr<RGWOIDCProvider>>& providers) override;
1031 virtual std::unique_ptr<Writer> get_append_writer(
1032 const DoutPrefixProvider* dpp, optional_yield y,
1033 rgw::sal::Object* obj, const rgw_user& owner,
1034 const rgw_placement_rule* ptail_placement_rule,
1035 const std::string& unique_tag, uint64_t position,
1036 uint64_t* cur_accounted_size) override;
1037 virtual std::unique_ptr<Writer> get_atomic_writer(
1038 const DoutPrefixProvider* dpp, optional_yield y,
1039 rgw::sal::Object* obj, const rgw_user& owner,
1040 const rgw_placement_rule* ptail_placement_rule, uint64_t olh_epoch,
1041 const std::string& unique_tag) override;
1042 virtual const std::string& get_compression_type(
1043 const rgw_placement_rule& rule) override;
1044 virtual bool valid_placement(const rgw_placement_rule& rule) override;
1045
1046 virtual void finalize(void) override;
1047
1048 virtual CephContext* ctx(void) override { return cctx; }
1049
1050 virtual int initialize(CephContext* cct,
1051 const DoutPrefixProvider* dpp) override;
1052 };
1053
1054 } // namespace rgw::sal