]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_sync_module.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rgw / rgw_sync_module.h
1 #ifndef CEPH_RGW_SYNC_MODULE_H
2 #define CEPH_RGW_SYNC_MODULE_H
3
4 #include "rgw_common.h"
5 #include "rgw_coroutine.h"
6
7 class RGWBucketInfo;
8 class RGWRemoteDataLog;
9 struct RGWDataSyncEnv;
10 struct rgw_bucket_entry_owner;
11 struct rgw_obj_key;
12
13
14 class RGWDataSyncModule {
15 public:
16 RGWDataSyncModule() {}
17 virtual ~RGWDataSyncModule() {}
18
19 virtual RGWCoroutine *sync_object(RGWDataSyncEnv *sync_env, RGWBucketInfo& bucket_info, rgw_obj_key& key, uint64_t versioned_epoch) = 0;
20 virtual RGWCoroutine *remove_object(RGWDataSyncEnv *sync_env, RGWBucketInfo& bucket_info, rgw_obj_key& key, real_time& mtime,
21 bool versioned, uint64_t versioned_epoch) = 0;
22 virtual RGWCoroutine *create_delete_marker(RGWDataSyncEnv *sync_env, RGWBucketInfo& bucket_info, rgw_obj_key& key, real_time& mtime,
23 rgw_bucket_entry_owner& owner, bool versioned, uint64_t versioned_epoch) = 0;
24 };
25
26 class RGWSyncModuleInstance {
27 public:
28 RGWSyncModuleInstance() {}
29 virtual ~RGWSyncModuleInstance() {}
30 virtual RGWDataSyncModule *get_data_handler() = 0;
31 };
32
33 typedef std::shared_ptr<RGWSyncModuleInstance> RGWSyncModuleInstanceRef;
34
35 class RGWSyncModule {
36
37 public:
38 RGWSyncModule() {}
39 virtual ~RGWSyncModule() {}
40
41 virtual bool supports_data_export() = 0;
42 virtual int create_instance(CephContext *cct, map<string, string>& config, RGWSyncModuleInstanceRef *instance) = 0;
43 };
44
45 typedef std::shared_ptr<RGWSyncModule> RGWSyncModuleRef;
46
47
48 class RGWSyncModulesManager {
49 Mutex lock;
50
51 map<string, RGWSyncModuleRef> modules;
52 public:
53 RGWSyncModulesManager() : lock("RGWSyncModulesManager") {}
54
55 void register_module(const string& name, RGWSyncModuleRef& module, bool is_default = false) {
56 Mutex::Locker l(lock);
57 modules[name] = module;
58 if (is_default) {
59 modules[string()] = module;
60 }
61 }
62
63 bool get_module(const string& name, RGWSyncModuleRef *module) {
64 Mutex::Locker l(lock);
65 auto iter = modules.find(name);
66 if (iter == modules.end()) {
67 return false;
68 }
69 *module = iter->second;
70 return true;
71 }
72
73
74 int supports_data_export(const string& name) {
75 RGWSyncModuleRef module;
76 if (!get_module(name, &module)) {
77 return -ENOENT;
78 }
79
80 return module.get()->supports_data_export();
81 }
82
83 int create_instance(CephContext *cct, const string& name, map<string, string>& config, RGWSyncModuleInstanceRef *instance) {
84 RGWSyncModuleRef module;
85 if (!get_module(name, &module)) {
86 return -ENOENT;
87 }
88
89 return module.get()->create_instance(cct, config, instance);
90 }
91 };
92
93 class RGWStatRemoteObjCBCR : public RGWCoroutine {
94 protected:
95 RGWDataSyncEnv *sync_env;
96
97 RGWBucketInfo bucket_info;
98 rgw_obj_key key;
99
100 ceph::real_time mtime;
101 uint64_t size;
102 map<string, bufferlist> attrs;
103 public:
104 RGWStatRemoteObjCBCR(RGWDataSyncEnv *_sync_env,
105 RGWBucketInfo& _bucket_info, rgw_obj_key& _key);
106 ~RGWStatRemoteObjCBCR() override {}
107
108 void set_result(ceph::real_time& _mtime,
109 uint64_t _size,
110 map<string, bufferlist>&& _attrs) {
111 mtime = _mtime;
112 size = _size;
113 attrs = std::move(_attrs);
114 }
115 };
116
117 class RGWCallStatRemoteObjCR : public RGWCoroutine {
118 ceph::real_time mtime;
119 uint64_t size{0};
120 map<string, bufferlist> attrs;
121
122 protected:
123 RGWDataSyncEnv *sync_env;
124
125 RGWBucketInfo bucket_info;
126 rgw_obj_key key;
127
128 public:
129 RGWCallStatRemoteObjCR(RGWDataSyncEnv *_sync_env,
130 RGWBucketInfo& _bucket_info, rgw_obj_key& _key);
131
132 ~RGWCallStatRemoteObjCR() override {}
133
134 int operate() override;
135
136 virtual RGWStatRemoteObjCBCR *allocate_callback() {
137 return nullptr;
138 }
139 };
140
141 void rgw_register_sync_modules(RGWSyncModulesManager *modules_manager);
142
143 #endif