]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab ft=cpp | |
3 | ||
4 | /* | |
5 | * Ceph - scalable distributed file system | |
6 | * | |
7 | * Copyright (C) 2019 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 | ||
9f95a23c TL |
18 | #include "rgw_user.h" |
19 | ||
f67539c2 TL |
20 | class RGWGetDataCB; |
21 | struct RGWObjState; | |
22 | class RGWAccessListFilter; | |
23 | class RGWLC; | |
24 | class RGWObjManifest; | |
25 | struct RGWZoneGroup; | |
26 | ||
27 | struct RGWUsageIter { | |
28 | string read_iter; | |
29 | uint32_t index; | |
30 | ||
31 | RGWUsageIter() : index(0) {} | |
32 | }; | |
33 | ||
34 | /** | |
35 | * @struct RGWClusterStat | |
36 | * Cluster-wide usage information | |
37 | */ | |
38 | struct RGWClusterStat { | |
39 | /// total device size | |
40 | uint64_t kb; | |
41 | /// total used | |
42 | uint64_t kb_used; | |
43 | /// total available/free | |
44 | uint64_t kb_avail; | |
45 | /// number of objects | |
46 | uint64_t num_objects; | |
47 | }; | |
48 | ||
49 | ||
9f95a23c TL |
50 | namespace rgw { namespace sal { |
51 | ||
52 | #define RGW_SAL_VERSION 1 | |
53 | ||
54 | class RGWUser; | |
55 | class RGWBucket; | |
56 | class RGWObject; | |
57 | class RGWBucketList; | |
f67539c2 TL |
58 | struct MPSerializer; |
59 | class Lifecycle; | |
9f95a23c | 60 | |
f67539c2 TL |
61 | enum AttrsMod { |
62 | ATTRSMOD_NONE = 0, | |
63 | ATTRSMOD_REPLACE = 1, | |
64 | ATTRSMOD_MERGE = 2 | |
65 | }; | |
9f95a23c | 66 | |
f67539c2 TL |
67 | using RGWAttrs = std::map<std::string, ceph::buffer::list>; |
68 | ||
b3b6e05e | 69 | class RGWStore { |
9f95a23c TL |
70 | public: |
71 | RGWStore() {} | |
72 | virtual ~RGWStore() = default; | |
73 | ||
f67539c2 TL |
74 | virtual std::unique_ptr<RGWUser> get_user(const rgw_user& u) = 0; |
75 | virtual std::unique_ptr<RGWObject> get_object(const rgw_obj_key& k) = 0; | |
b3b6e05e | 76 | virtual int get_bucket(const DoutPrefixProvider *dpp, RGWUser* u, const rgw_bucket& b, std::unique_ptr<RGWBucket>* bucket, optional_yield y) = 0; |
f67539c2 | 77 | virtual int get_bucket(RGWUser* u, const RGWBucketInfo& i, std::unique_ptr<RGWBucket>* bucket) = 0; |
b3b6e05e TL |
78 | virtual int get_bucket(const DoutPrefixProvider *dpp, RGWUser* u, const std::string& tenant, const std::string& name, std::unique_ptr<RGWBucket>* bucket, optional_yield y) = 0; |
79 | virtual int create_bucket(const DoutPrefixProvider *dpp, | |
80 | RGWUser& u, const rgw_bucket& b, | |
f67539c2 TL |
81 | const std::string& zonegroup_id, |
82 | rgw_placement_rule& placement_rule, | |
83 | std::string& swift_ver_location, | |
84 | const RGWQuotaInfo * pquota_info, | |
85 | const RGWAccessControlPolicy& policy, | |
86 | RGWAttrs& attrs, | |
87 | RGWBucketInfo& info, | |
88 | obj_version& ep_objv, | |
89 | bool exclusive, | |
90 | bool obj_lock_enabled, | |
91 | bool *existed, | |
92 | req_info& req_info, | |
93 | std::unique_ptr<RGWBucket>* bucket, | |
94 | optional_yield y) = 0; | |
9f95a23c | 95 | virtual RGWBucketList* list_buckets(void) = 0; |
f67539c2 | 96 | virtual bool is_meta_master() = 0; |
b3b6e05e | 97 | virtual int forward_request_to_master(const DoutPrefixProvider *dpp, RGWUser* user, obj_version *objv, |
f67539c2 TL |
98 | bufferlist& in_data, JSONParser *jp, req_info& info, |
99 | optional_yield y) = 0; | |
b3b6e05e | 100 | virtual int defer_gc(const DoutPrefixProvider *dpp, RGWObjectCtx *rctx, RGWBucket* bucket, RGWObject* obj, |
f67539c2 TL |
101 | optional_yield y) = 0; |
102 | virtual const RGWZoneGroup& get_zonegroup() = 0; | |
103 | virtual int get_zonegroup(const string& id, RGWZoneGroup& zonegroup) = 0; | |
104 | virtual int cluster_stat(RGWClusterStat& stats) = 0; | |
105 | virtual std::unique_ptr<Lifecycle> get_lifecycle(void) = 0; | |
106 | virtual RGWLC* get_rgwlc(void) = 0; | |
b3b6e05e | 107 | virtual int delete_raw_obj(const DoutPrefixProvider *dpp, const rgw_raw_obj& obj) = 0; |
f67539c2 | 108 | virtual void get_raw_obj(const rgw_placement_rule& placement_rule, const rgw_obj& obj, rgw_raw_obj* raw_obj) = 0; |
b3b6e05e | 109 | virtual int get_raw_chunk_size(const DoutPrefixProvider *dpp, const rgw_raw_obj& obj, uint64_t* chunk_size) = 0; |
9f95a23c TL |
110 | |
111 | virtual void finalize(void)=0; | |
112 | ||
113 | virtual CephContext *ctx(void)=0; | |
f67539c2 TL |
114 | |
115 | // get the location of where lua packages are installed | |
116 | virtual const std::string& get_luarocks_path() const = 0; | |
117 | // set the location of where lua packages are installed | |
118 | virtual void set_luarocks_path(const std::string& path) = 0; | |
9f95a23c TL |
119 | }; |
120 | ||
121 | class RGWUser { | |
122 | protected: | |
123 | RGWUserInfo info; | |
124 | ||
125 | public: | |
126 | RGWUser() : info() {} | |
127 | RGWUser(const rgw_user& _u) : info() { info.user_id = _u; } | |
128 | RGWUser(const RGWUserInfo& _i) : info(_i) {} | |
129 | virtual ~RGWUser() = default; | |
130 | ||
b3b6e05e TL |
131 | virtual int list_buckets(const DoutPrefixProvider *dpp, |
132 | const std::string& marker, const std::string& end_marker, | |
f67539c2 TL |
133 | uint64_t max, bool need_stats, RGWBucketList& buckets, |
134 | optional_yield y) = 0; | |
135 | virtual RGWBucket* create_bucket(rgw_bucket& bucket, ceph::real_time creation_time) = 0; | |
9f95a23c TL |
136 | friend class RGWBucket; |
137 | virtual std::string& get_display_name() { return info.display_name; } | |
138 | ||
139 | std::string& get_tenant() { return info.user_id.tenant; } | |
140 | const rgw_user& get_id() const { return info.user_id; } | |
141 | uint32_t get_type() const { return info.type; } | |
142 | int32_t get_max_buckets() const { return info.max_buckets; } | |
143 | const RGWUserCaps& get_caps() const { return info.caps; } | |
f67539c2 | 144 | static bool empty(RGWUser* u) { return (!u || u->info.user_id.id.empty()); } |
9f95a23c | 145 | |
f67539c2 | 146 | /* Placeholders */ |
b3b6e05e | 147 | virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y) = 0; |
9f95a23c | 148 | |
f67539c2 | 149 | /* dang temporary; will be removed when User is complete */ |
9f95a23c TL |
150 | rgw_user& get_user() { return info.user_id; } |
151 | RGWUserInfo& get_info() { return info; } | |
f67539c2 TL |
152 | |
153 | friend inline ostream& operator<<(ostream& out, const RGWUser& u) { | |
154 | out << u.info.user_id; | |
155 | return out; | |
156 | } | |
157 | ||
158 | friend inline ostream& operator<<(ostream& out, const RGWUser* u) { | |
159 | if (!u) | |
160 | out << "<NULL>"; | |
161 | else | |
162 | out << u->info.user_id; | |
163 | return out; | |
164 | } | |
165 | ||
166 | friend inline ostream& operator<<(ostream& out, const std::unique_ptr<RGWUser>& p) { | |
167 | out << p.get(); | |
168 | return out; | |
169 | } | |
170 | ||
9f95a23c TL |
171 | }; |
172 | ||
173 | class RGWBucket { | |
174 | protected: | |
175 | RGWBucketEnt ent; | |
176 | RGWBucketInfo info; | |
f67539c2 | 177 | RGWUser* owner = nullptr; |
9f95a23c | 178 | RGWAttrs attrs; |
f67539c2 TL |
179 | obj_version bucket_version; |
180 | ceph::real_time mtime; | |
9f95a23c TL |
181 | |
182 | public: | |
f67539c2 TL |
183 | |
184 | struct ListParams { | |
185 | std::string prefix; | |
186 | std::string delim; | |
187 | rgw_obj_key marker; | |
188 | rgw_obj_key end_marker; | |
189 | std::string ns; | |
190 | bool enforce_ns{true}; | |
191 | RGWAccessListFilter *filter{nullptr}; | |
192 | bool list_versions{false}; | |
193 | bool allow_unordered{false}; | |
194 | int shard_id{-1}; | |
195 | }; | |
196 | struct ListResults { | |
197 | vector<rgw_bucket_dir_entry> objs; | |
198 | map<std::string, bool> common_prefixes; | |
199 | bool is_truncated{false}; | |
200 | rgw_obj_key next_marker; | |
201 | }; | |
202 | ||
203 | RGWBucket() = default; | |
204 | RGWBucket(const rgw_bucket& _b) { ent.bucket = _b; info.bucket = _b; } | |
205 | RGWBucket(const RGWBucketEnt& _e) : ent(_e) { | |
206 | info.bucket = ent.bucket; | |
207 | info.placement_rule = ent.placement_rule; | |
208 | info.creation_time = ent.creation_time; | |
209 | } | |
210 | RGWBucket(const RGWBucketInfo& _i) : info(_i) { | |
211 | ent.bucket = info.bucket; | |
212 | ent.placement_rule = info.placement_rule; | |
213 | ent.creation_time = info.creation_time; | |
214 | } | |
215 | RGWBucket(const rgw_bucket& _b, RGWUser* _u) : | |
216 | owner(_u) { ent.bucket = _b; info.bucket = _b; } | |
217 | RGWBucket(const RGWBucketEnt& _e, RGWUser* _u) : ent(_e), owner(_u) { | |
218 | info.bucket = ent.bucket; | |
219 | info.placement_rule = ent.placement_rule; | |
220 | info.creation_time = ent.creation_time; | |
221 | } | |
222 | RGWBucket(const RGWBucketInfo& _i, RGWUser* _u) : info(_i), owner(_u) { | |
223 | ent.bucket = info.bucket; | |
224 | ent.placement_rule = info.placement_rule; | |
225 | ent.creation_time = info.creation_time; | |
226 | } | |
9f95a23c TL |
227 | virtual ~RGWBucket() = default; |
228 | ||
b3b6e05e | 229 | virtual int load_by_name(const DoutPrefixProvider *dpp, const std::string& tenant, const std::string& bucket_name, const std::string bucket_instance_id, RGWSysObjectCtx *rctx, optional_yield y) = 0; |
f67539c2 | 230 | virtual std::unique_ptr<RGWObject> get_object(const rgw_obj_key& key) = 0; |
b3b6e05e | 231 | virtual int list(const DoutPrefixProvider *dpp, ListParams&, int, ListResults&, optional_yield y) = 0; |
9f95a23c TL |
232 | virtual RGWObject* create_object(const rgw_obj_key& key /* Attributes */) = 0; |
233 | virtual RGWAttrs& get_attrs(void) { return attrs; } | |
f67539c2 | 234 | virtual int set_attrs(RGWAttrs a) { attrs = a; return 0; } |
a4b75251 | 235 | virtual int remove_bucket(const DoutPrefixProvider *dpp, bool delete_children, bool forward_to_master, req_info* req_info, optional_yield y) = 0; |
9f95a23c | 236 | virtual RGWAccessControlPolicy& get_acl(void) = 0; |
b3b6e05e TL |
237 | virtual int set_acl(const DoutPrefixProvider *dpp, RGWAccessControlPolicy& acl, optional_yield y) = 0; |
238 | virtual int get_bucket_info(const DoutPrefixProvider *dpp, optional_yield y) = 0; | |
239 | virtual int get_bucket_stats(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, int shard_id, | |
9f95a23c TL |
240 | std::string *bucket_ver, std::string *master_ver, |
241 | std::map<RGWObjCategory, RGWStorageStats>& stats, | |
242 | std::string *max_marker = nullptr, | |
243 | bool *syncstopped = nullptr) = 0; | |
b3b6e05e TL |
244 | virtual int read_bucket_stats(const DoutPrefixProvider *dpp, optional_yield y) = 0; |
245 | virtual int sync_user_stats(const DoutPrefixProvider *dpp, optional_yield y) = 0; | |
246 | virtual int update_container_stats(const DoutPrefixProvider *dpp) = 0; | |
247 | virtual int check_bucket_shards(const DoutPrefixProvider *dpp) = 0; | |
248 | virtual int link(const DoutPrefixProvider *dpp, RGWUser* new_user, optional_yield y) = 0; | |
9f95a23c | 249 | virtual int unlink(RGWUser* new_user, optional_yield y) = 0; |
b3b6e05e TL |
250 | virtual int chown(RGWUser* new_user, RGWUser* old_user, optional_yield y, const DoutPrefixProvider *dpp) = 0; |
251 | virtual int put_instance_info(const DoutPrefixProvider *dpp, bool exclusive, ceph::real_time mtime) = 0; | |
f67539c2 TL |
252 | virtual bool is_owner(RGWUser* user) = 0; |
253 | virtual RGWUser* get_owner(void) { return owner; }; | |
254 | virtual ACLOwner get_acl_owner(void) { return ACLOwner(info.owner); }; | |
b3b6e05e | 255 | virtual int check_empty(const DoutPrefixProvider *dpp, optional_yield y) = 0; |
f67539c2 | 256 | virtual int check_quota(RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota, uint64_t obj_size, optional_yield y, bool check_size_only = false) = 0; |
b3b6e05e TL |
257 | virtual int set_instance_attrs(const DoutPrefixProvider *dpp, RGWAttrs& attrs, optional_yield y) = 0; |
258 | virtual int try_refresh_info(const DoutPrefixProvider *dpp, ceph::real_time *pmtime) = 0; | |
259 | virtual int read_usage(const DoutPrefixProvider *dpp, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries, | |
f67539c2 TL |
260 | bool *is_truncated, RGWUsageIter& usage_iter, |
261 | map<rgw_user_bucket, rgw_usage_log_entry>& usage) = 0; | |
262 | ||
263 | bool empty() const { return info.bucket.name.empty(); } | |
264 | const std::string& get_name() const { return info.bucket.name; } | |
265 | const std::string& get_tenant() const { return info.bucket.tenant; } | |
266 | const std::string& get_marker() const { return info.bucket.marker; } | |
267 | const std::string& get_bucket_id() const { return info.bucket.bucket_id; } | |
9f95a23c TL |
268 | size_t get_size() const { return ent.size; } |
269 | size_t get_size_rounded() const { return ent.size_rounded; } | |
270 | uint64_t get_count() const { return ent.count; } | |
f67539c2 TL |
271 | rgw_placement_rule& get_placement_rule() { return info.placement_rule; } |
272 | ceph::real_time& get_creation_time() { return info.creation_time; } | |
273 | ceph::real_time& get_modification_time() { return mtime; } | |
274 | obj_version& get_version() { return bucket_version; } | |
275 | void set_version(obj_version &ver) { bucket_version = ver; } | |
276 | bool versioned() { return info.versioned(); } | |
277 | bool versioning_enabled() { return info.versioning_enabled(); } | |
9f95a23c TL |
278 | |
279 | void convert(cls_user_bucket_entry *b) const { | |
280 | ent.convert(b); | |
281 | } | |
282 | ||
f67539c2 TL |
283 | static bool empty(RGWBucket* b) { return (!b || b->empty()); } |
284 | virtual std::unique_ptr<RGWBucket> clone() = 0; | |
285 | ||
9f95a23c | 286 | /* dang - This is temporary, until the API is completed */ |
f67539c2 | 287 | rgw_bucket& get_key() { return info.bucket; } |
9f95a23c TL |
288 | RGWBucketInfo& get_info() { return info; } |
289 | ||
290 | friend inline ostream& operator<<(ostream& out, const RGWBucket& b) { | |
f67539c2 TL |
291 | out << b.info.bucket; |
292 | return out; | |
293 | } | |
294 | ||
295 | friend inline ostream& operator<<(ostream& out, const RGWBucket* b) { | |
296 | if (!b) | |
297 | out << "<NULL>"; | |
298 | else | |
299 | out << b->info.bucket; | |
300 | return out; | |
301 | } | |
302 | ||
303 | friend inline ostream& operator<<(ostream& out, const std::unique_ptr<RGWBucket>& p) { | |
304 | out << p.get(); | |
9f95a23c TL |
305 | return out; |
306 | } | |
307 | ||
308 | ||
309 | friend class RGWBucketList; | |
310 | protected: | |
f67539c2 | 311 | virtual void set_ent(RGWBucketEnt& _ent) { ent = _ent; info.bucket = ent.bucket; info.placement_rule = ent.placement_rule; } |
9f95a23c TL |
312 | }; |
313 | ||
f67539c2 | 314 | |
9f95a23c | 315 | class RGWBucketList { |
f67539c2 | 316 | std::map<std::string, std::unique_ptr<RGWBucket>> buckets; |
9f95a23c TL |
317 | bool truncated; |
318 | ||
319 | public: | |
320 | RGWBucketList() : buckets(), truncated(false) {} | |
f67539c2 TL |
321 | RGWBucketList(RGWBucketList&& _bl) : |
322 | buckets(std::move(_bl.buckets)), | |
323 | truncated(_bl.truncated) | |
324 | { } | |
325 | RGWBucketList& operator=(const RGWBucketList&) = delete; | |
326 | RGWBucketList& operator=(RGWBucketList&& _bl) { | |
327 | for (auto& ent : _bl.buckets) { | |
328 | buckets.emplace(ent.first, std::move(ent.second)); | |
329 | } | |
330 | truncated = _bl.truncated; | |
331 | return *this; | |
332 | }; | |
9f95a23c | 333 | |
f67539c2 | 334 | map<std::string, std::unique_ptr<RGWBucket>>& get_buckets() { return buckets; } |
9f95a23c TL |
335 | bool is_truncated(void) const { return truncated; } |
336 | void set_truncated(bool trunc) { truncated = trunc; } | |
f67539c2 TL |
337 | void add(std::unique_ptr<RGWBucket> bucket) { |
338 | buckets.emplace(bucket->info.bucket.name, std::move(bucket)); | |
9f95a23c TL |
339 | } |
340 | size_t count() const { return buckets.size(); } | |
f67539c2 TL |
341 | void clear(void) { |
342 | buckets.clear(); | |
343 | truncated = false; | |
344 | } | |
345 | }; | |
9f95a23c TL |
346 | |
347 | class RGWObject { | |
348 | protected: | |
349 | rgw_obj_key key; | |
f67539c2 TL |
350 | RGWBucket* bucket; |
351 | std::string index_hash_source; | |
352 | uint64_t obj_size; | |
353 | RGWAttrs attrs; | |
354 | ceph::real_time mtime; | |
355 | bool delete_marker{false}; | |
356 | bool in_extra_data{false}; | |
9f95a23c TL |
357 | |
358 | public: | |
f67539c2 TL |
359 | |
360 | struct ReadOp { | |
361 | struct Params { | |
362 | const ceph::real_time *mod_ptr{nullptr}; | |
363 | const ceph::real_time *unmod_ptr{nullptr}; | |
364 | bool high_precision_time{false}; | |
365 | uint32_t mod_zone_id{0}; | |
366 | uint64_t mod_pg_ver{0}; | |
367 | const char *if_match{nullptr}; | |
368 | const char *if_nomatch{nullptr}; | |
369 | ceph::real_time *lastmod{nullptr}; | |
370 | rgw_obj *target_obj{nullptr}; // XXX dang remove? | |
371 | } params; | |
372 | ||
373 | struct Result { | |
374 | rgw_raw_obj head_obj; | |
375 | ||
376 | Result() : head_obj() {} | |
377 | } result; | |
378 | ||
379 | virtual ~ReadOp() = default; | |
380 | ||
b3b6e05e TL |
381 | virtual int prepare(optional_yield y, const DoutPrefixProvider *dpp) = 0; |
382 | virtual int read(int64_t ofs, int64_t end, bufferlist& bl, optional_yield y, const DoutPrefixProvider *dpp) = 0; | |
383 | virtual int iterate(const DoutPrefixProvider *dpp, int64_t ofs, int64_t end, RGWGetDataCB *cb, optional_yield y) = 0; | |
384 | virtual int get_manifest(const DoutPrefixProvider *dpp, RGWObjManifest **pmanifest, optional_yield y) = 0; | |
385 | virtual int get_attr(const DoutPrefixProvider *dpp, const char *name, bufferlist& dest, optional_yield y) = 0; | |
f67539c2 TL |
386 | }; |
387 | ||
388 | struct WriteOp { | |
389 | struct Params { | |
390 | bool versioning_disabled{false}; | |
391 | ceph::real_time* mtime{nullptr}; | |
392 | RGWAttrs* rmattrs{nullptr}; | |
393 | const bufferlist* data{nullptr}; | |
394 | RGWObjManifest* manifest{nullptr}; | |
395 | const string* ptag{nullptr}; | |
396 | list<rgw_obj_index_key>* remove_objs{nullptr}; | |
397 | ceph::real_time set_mtime; | |
398 | ACLOwner owner; | |
399 | RGWObjCategory category{RGWObjCategory::Main}; | |
400 | int flags{0}; | |
401 | const char* if_match{nullptr}; | |
402 | const char* if_nomatch{nullptr}; | |
403 | std::optional<uint64_t> olh_epoch; | |
404 | ceph::real_time delete_at; | |
405 | bool canceled{false}; | |
406 | const string* user_data{nullptr}; | |
407 | rgw_zone_set* zones_trace{nullptr}; | |
408 | bool modify_tail{false}; | |
409 | bool completeMultipart{false}; | |
410 | bool appendable{false}; | |
411 | RGWAttrs* attrs{nullptr}; | |
412 | } params; | |
413 | ||
414 | virtual ~WriteOp() = default; | |
415 | ||
416 | virtual int prepare(optional_yield y) = 0; | |
b3b6e05e | 417 | virtual int write_meta(const DoutPrefixProvider *dpp, uint64_t size, uint64_t accounted_size, optional_yield y) = 0; |
f67539c2 TL |
418 | //virtual int write_data(const char *data, uint64_t ofs, uint64_t len, bool exclusive) = 0; |
419 | }; | |
420 | ||
421 | RGWObject() | |
422 | : key(), | |
423 | bucket(nullptr), | |
424 | index_hash_source(), | |
425 | obj_size(), | |
426 | attrs(), | |
427 | mtime() {} | |
428 | RGWObject(const rgw_obj_key& _k) | |
429 | : key(_k), | |
430 | bucket(), | |
431 | index_hash_source(), | |
432 | obj_size(), | |
433 | attrs(), | |
434 | mtime() {} | |
435 | RGWObject(const rgw_obj_key& _k, RGWBucket* _b) | |
436 | : key(_k), | |
437 | bucket(_b), | |
438 | index_hash_source(), | |
439 | obj_size(), | |
440 | attrs(), | |
441 | mtime() {} | |
442 | RGWObject(RGWObject& _o) = default; | |
443 | ||
9f95a23c TL |
444 | virtual ~RGWObject() = default; |
445 | ||
446 | virtual int read(off_t offset, off_t length, std::iostream& stream) = 0; | |
447 | virtual int write(off_t offset, off_t length, std::iostream& stream) = 0; | |
b3b6e05e | 448 | virtual int delete_object(const DoutPrefixProvider *dpp, RGWObjectCtx* obj_ctx, ACLOwner obj_owner, |
f67539c2 TL |
449 | ACLOwner bucket_owner, ceph::real_time unmod_since, |
450 | bool high_precision_time, uint64_t epoch, | |
b3b6e05e TL |
451 | std::string& version_id, |
452 | optional_yield y, | |
453 | bool prevent_versioning = false) = 0; | |
f67539c2 TL |
454 | virtual int copy_object(RGWObjectCtx& obj_ctx, RGWUser* user, |
455 | req_info *info, const rgw_zone_id& source_zone, | |
456 | rgw::sal::RGWObject* dest_object, rgw::sal::RGWBucket* dest_bucket, | |
457 | rgw::sal::RGWBucket* src_bucket, | |
458 | const rgw_placement_rule& dest_placement, | |
459 | ceph::real_time *src_mtime, ceph::real_time *mtime, | |
460 | const ceph::real_time *mod_ptr, const ceph::real_time *unmod_ptr, | |
461 | bool high_precision_time, | |
462 | const char *if_match, const char *if_nomatch, | |
463 | AttrsMod attrs_mod, bool copy_if_newer, RGWAttrs& attrs, | |
464 | RGWObjCategory category, uint64_t olh_epoch, | |
465 | boost::optional<ceph::real_time> delete_at, | |
466 | string *version_id, string *tag, string *etag, | |
467 | void (*progress_cb)(off_t, void *), void *progress_data, | |
468 | const DoutPrefixProvider *dpp, optional_yield y) = 0; | |
9f95a23c TL |
469 | virtual RGWAccessControlPolicy& get_acl(void) = 0; |
470 | virtual int set_acl(const RGWAccessControlPolicy& acl) = 0; | |
f67539c2 TL |
471 | virtual void set_atomic(RGWObjectCtx *rctx) const = 0; |
472 | virtual void set_prefetch_data(RGWObjectCtx *rctx) = 0; | |
473 | ||
474 | bool empty() const { return key.empty(); } | |
475 | const std::string &get_name() const { return key.name; } | |
476 | ||
b3b6e05e TL |
477 | virtual int get_obj_state(const DoutPrefixProvider *dpp, RGWObjectCtx *rctx, RGWBucket& bucket, RGWObjState **state, optional_yield y, bool follow_olh = false) = 0; |
478 | virtual int set_obj_attrs(const DoutPrefixProvider *dpp, RGWObjectCtx* rctx, RGWAttrs* setattrs, RGWAttrs* delattrs, optional_yield y, rgw_obj* target_obj = NULL) = 0; | |
479 | virtual int get_obj_attrs(RGWObjectCtx *rctx, optional_yield y, const DoutPrefixProvider *dpp, rgw_obj* target_obj = NULL) = 0; | |
480 | virtual int modify_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, bufferlist& attr_val, optional_yield y, const DoutPrefixProvider *dpp) = 0; | |
481 | virtual int delete_obj_attrs(const DoutPrefixProvider *dpp, RGWObjectCtx *rctx, const char *attr_name, optional_yield y) = 0; | |
f67539c2 TL |
482 | virtual int copy_obj_data(RGWObjectCtx& rctx, RGWBucket* dest_bucket, RGWObject* dest_obj, uint16_t olh_epoch, std::string* petag, const DoutPrefixProvider *dpp, optional_yield y) = 0; |
483 | virtual bool is_expired() = 0; | |
484 | virtual void gen_rand_obj_instance_name() = 0; | |
485 | virtual void raw_obj_to_obj(const rgw_raw_obj& raw_obj) = 0; | |
486 | virtual void get_raw_obj(rgw_raw_obj* raw_obj) = 0; | |
b3b6e05e | 487 | virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) = 0; |
f67539c2 TL |
488 | virtual int transition(RGWObjectCtx& rctx, |
489 | RGWBucket* bucket, | |
490 | const rgw_placement_rule& placement_rule, | |
491 | const real_time& mtime, | |
492 | uint64_t olh_epoch, | |
493 | const DoutPrefixProvider *dpp, | |
494 | optional_yield y) = 0; | |
b3b6e05e TL |
495 | virtual int get_max_chunk_size(const DoutPrefixProvider *dpp, |
496 | rgw_placement_rule placement_rule, | |
f67539c2 TL |
497 | uint64_t* max_chunk_size, |
498 | uint64_t* alignment = nullptr) = 0; | |
499 | virtual void get_max_aligned_size(uint64_t size, uint64_t alignment, uint64_t *max_size) = 0; | |
500 | virtual bool placement_rules_match(rgw_placement_rule& r1, rgw_placement_rule& r2) = 0; | |
9f95a23c | 501 | |
f67539c2 TL |
502 | RGWAttrs& get_attrs(void) { return attrs; } |
503 | const RGWAttrs& get_attrs(void) const { return attrs; } | |
504 | ceph::real_time get_mtime(void) const { return mtime; } | |
505 | uint64_t get_obj_size(void) const { return obj_size; } | |
506 | RGWBucket* get_bucket(void) const { return bucket; } | |
507 | void set_bucket(RGWBucket* b) { bucket = b; } | |
508 | std::string get_hash_source(void) { return index_hash_source; } | |
509 | void set_hash_source(std::string s) { index_hash_source = s; } | |
510 | std::string get_oid(void) const { return key.get_oid(); } | |
511 | bool get_delete_marker(void) { return delete_marker; } | |
512 | bool get_in_extra_data(void) { return in_extra_data; } | |
513 | void set_in_extra_data(bool i) { in_extra_data = i; } | |
514 | int range_to_ofs(uint64_t obj_size, int64_t &ofs, int64_t &end); | |
515 | void set_obj_size(uint64_t s) { obj_size = s; } | |
516 | virtual void set_name(const std::string& n) { key = n; } | |
517 | virtual void set_key(const rgw_obj_key& k) { key = k; } | |
518 | virtual rgw_obj get_obj(void) const { | |
519 | rgw_obj obj(bucket->get_key(), key); | |
520 | obj.set_in_extra_data(in_extra_data); | |
521 | obj.index_hash_source = index_hash_source; | |
522 | return obj; | |
523 | } | |
9f95a23c | 524 | |
f67539c2 TL |
525 | /* Swift versioning */ |
526 | virtual int swift_versioning_restore(RGWObjectCtx* obj_ctx, | |
527 | bool& restored, /* out */ | |
528 | const DoutPrefixProvider *dpp) = 0; | |
529 | virtual int swift_versioning_copy(RGWObjectCtx* obj_ctx, | |
530 | const DoutPrefixProvider *dpp, | |
531 | optional_yield y) = 0; | |
9f95a23c | 532 | |
f67539c2 TL |
533 | /* OPs */ |
534 | virtual std::unique_ptr<ReadOp> get_read_op(RGWObjectCtx*) = 0; | |
535 | virtual std::unique_ptr<WriteOp> get_write_op(RGWObjectCtx*) = 0; | |
9f95a23c | 536 | |
f67539c2 | 537 | /* OMAP */ |
b3b6e05e | 538 | virtual int omap_get_vals_by_keys(const DoutPrefixProvider *dpp, const std::string& oid, |
f67539c2 TL |
539 | const std::set<std::string>& keys, |
540 | RGWAttrs *vals) = 0; | |
b3b6e05e | 541 | virtual int omap_set_val_by_key(const DoutPrefixProvider *dpp, const std::string& key, bufferlist& val, |
f67539c2 | 542 | bool must_exist, optional_yield y) = 0; |
9f95a23c | 543 | |
f67539c2 TL |
544 | static bool empty(RGWObject* o) { return (!o || o->empty()); } |
545 | virtual std::unique_ptr<RGWObject> clone() = 0; | |
9f95a23c | 546 | |
f67539c2 | 547 | /* dang - Not sure if we want this, but it simplifies things a lot */ |
9f95a23c | 548 | |
f67539c2 TL |
549 | /* dang - This is temporary, until the API is completed */ |
550 | rgw_obj_key& get_key() { return key; } | |
551 | void set_instance(const std::string &i) { key.set_instance(i); } | |
552 | const std::string &get_instance() const { return key.instance; } | |
553 | bool have_instance(void) { return key.have_instance(); } | |
554 | ||
555 | friend inline ostream& operator<<(ostream& out, const RGWObject& o) { | |
556 | if (o.bucket) | |
557 | out << o.bucket << ":"; | |
558 | out << o.key; | |
559 | return out; | |
9f95a23c | 560 | } |
f67539c2 TL |
561 | friend inline ostream& operator<<(ostream& out, const RGWObject* o) { |
562 | if (!o) | |
563 | out << "<NULL>"; | |
564 | else | |
565 | out << *o; | |
566 | return out; | |
9f95a23c | 567 | } |
f67539c2 TL |
568 | friend inline ostream& operator<<(ostream& out, const std::unique_ptr<RGWObject>& p) { |
569 | out << p.get(); | |
570 | return out; | |
9f95a23c | 571 | } |
9f95a23c TL |
572 | }; |
573 | ||
f67539c2 TL |
574 | struct Serializer { |
575 | Serializer() = default; | |
576 | virtual ~Serializer() = default; | |
9f95a23c | 577 | |
b3b6e05e | 578 | virtual int try_lock(const DoutPrefixProvider *dpp, utime_t dur, optional_yield y) = 0; |
f67539c2 TL |
579 | virtual int unlock() = 0; |
580 | }; | |
9f95a23c | 581 | |
f67539c2 TL |
582 | struct MPSerializer : Serializer { |
583 | bool locked; | |
584 | std::string oid; | |
585 | MPSerializer() : locked(false) {} | |
586 | virtual ~MPSerializer() = default; | |
9f95a23c | 587 | |
f67539c2 TL |
588 | void clear_locked() { |
589 | locked = false; | |
590 | } | |
591 | }; | |
9f95a23c | 592 | |
f67539c2 TL |
593 | struct LCSerializer : Serializer { |
594 | LCSerializer() {} | |
595 | virtual ~LCSerializer() = default; | |
596 | }; | |
9f95a23c | 597 | |
f67539c2 TL |
598 | class Lifecycle { |
599 | public: | |
600 | struct LCHead { | |
601 | time_t start_date{0}; | |
602 | std::string marker; | |
603 | ||
604 | LCHead() = default; | |
605 | LCHead(time_t _date, std::string& _marker) : start_date(_date), marker(_marker) {} | |
606 | }; | |
607 | ||
608 | struct LCEntry { | |
609 | std::string bucket; | |
610 | uint64_t start_time{0}; | |
611 | uint32_t status{0}; | |
612 | ||
613 | LCEntry() = default; | |
614 | LCEntry(std::string& _bucket, uint64_t _time, uint32_t _status) : bucket(_bucket), start_time(_time), status(_status) {} | |
615 | }; | |
616 | ||
617 | Lifecycle() = default; | |
618 | virtual ~Lifecycle() = default; | |
619 | ||
620 | virtual int get_entry(const string& oid, const std::string& marker, LCEntry& entry) = 0; | |
621 | virtual int get_next_entry(const string& oid, std::string& marker, LCEntry& entry) = 0; | |
622 | virtual int set_entry(const string& oid, const LCEntry& entry) = 0; | |
623 | virtual int list_entries(const string& oid, const string& marker, | |
624 | uint32_t max_entries, vector<LCEntry>& entries) = 0; | |
625 | virtual int rm_entry(const string& oid, const LCEntry& entry) = 0; | |
626 | virtual int get_head(const string& oid, LCHead& head) = 0; | |
627 | virtual int put_head(const string& oid, const LCHead& head) = 0; | |
628 | ||
629 | virtual LCSerializer* get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) = 0; | |
9f95a23c TL |
630 | }; |
631 | ||
632 | } } // namespace rgw::sal | |
633 |