]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_sal.h
542844d03924868770b2629e11559fafe7c25378
[ceph.git] / ceph / src / rgw / rgw_sal.h
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
18 #include "rgw_rados.h"
19 #include "rgw_user.h"
20
21 namespace rgw { namespace sal {
22
23 #define RGW_SAL_VERSION 1
24
25 class RGWUser;
26 class RGWBucket;
27 class RGWObject;
28 class RGWBucketList;
29
30 typedef std::map<std::string, ceph::bufferlist> RGWAttrs;
31
32 class RGWStore {
33 public:
34 RGWStore() {}
35 virtual ~RGWStore() = default;
36
37 virtual RGWUser* get_user(const rgw_user& u) = 0;
38 virtual int get_bucket(RGWUser& u, const rgw_bucket& b, RGWBucket** bucket) = 0;
39 //virtual RGWBucket* create_bucket(RGWUser& u, const rgw_bucket& b) = 0;
40 virtual RGWBucketList* list_buckets(void) = 0;
41
42 virtual void finalize(void)=0;
43
44 virtual CephContext *ctx(void)=0;
45 };
46
47 class RGWUser {
48 protected:
49 RGWUserInfo info;
50
51 public:
52 RGWUser() : info() {}
53 RGWUser(const rgw_user& _u) : info() { info.user_id = _u; }
54 RGWUser(const RGWUserInfo& _i) : info(_i) {}
55 virtual ~RGWUser() = default;
56
57 virtual int list_buckets(const string& marker, const string& end_marker,
58 uint64_t max, bool need_stats, RGWBucketList& buckets) = 0;
59 virtual RGWBucket* add_bucket(rgw_bucket& bucket, ceph::real_time creation_time) = 0;
60 friend class RGWBucket;
61 virtual std::string& get_display_name() { return info.display_name; }
62
63 std::string& get_tenant() { return info.user_id.tenant; }
64 const rgw_user& get_id() const { return info.user_id; }
65 uint32_t get_type() const { return info.type; }
66 int32_t get_max_buckets() const { return info.max_buckets; }
67 const RGWUserCaps& get_caps() const { return info.caps; }
68
69
70 /* xxx dang temporary; will be removed when User is complete */
71 rgw_user& get_user() { return info.user_id; }
72 RGWUserInfo& get_info() { return info; }
73 };
74
75 class RGWBucket {
76 protected:
77 RGWBucketEnt ent;
78 RGWBucketInfo info;
79 RGWUser *owner;
80 RGWAttrs attrs;
81
82 public:
83 RGWBucket() : ent(), owner(nullptr), attrs() {}
84 RGWBucket(const rgw_bucket& _b) : ent(), attrs() { ent.bucket = _b; }
85 RGWBucket(const RGWBucketEnt& _e) : ent(_e), attrs() {}
86 virtual ~RGWBucket() = default;
87
88 virtual RGWObject* get_object(const rgw_obj_key& key) = 0;
89 virtual RGWBucketList* list(void) = 0;
90 virtual RGWObject* create_object(const rgw_obj_key& key /* Attributes */) = 0;
91 virtual RGWAttrs& get_attrs(void) { return attrs; }
92 virtual int set_attrs(RGWAttrs& a) { attrs = a; return 0; }
93 virtual int remove_bucket(bool delete_children, optional_yield y) = 0;
94 virtual RGWAccessControlPolicy& get_acl(void) = 0;
95 virtual int set_acl(RGWAccessControlPolicy& acl, optional_yield y) = 0;
96 virtual int get_bucket_info(optional_yield y) = 0;
97 virtual int get_bucket_stats(RGWBucketInfo& bucket_info, int shard_id,
98 std::string *bucket_ver, std::string *master_ver,
99 std::map<RGWObjCategory, RGWStorageStats>& stats,
100 std::string *max_marker = nullptr,
101 bool *syncstopped = nullptr) = 0;
102 virtual int read_bucket_stats(optional_yield y) = 0;
103 virtual int sync_user_stats() = 0;
104 virtual int update_container_stats(void) = 0;
105 virtual int check_bucket_shards(void) = 0;
106 virtual int link(RGWUser* new_user, optional_yield y) = 0;
107 virtual int unlink(RGWUser* new_user, optional_yield y) = 0;
108 virtual int chown(RGWUser* new_user, RGWUser* old_user, optional_yield y) = 0;
109 virtual bool is_owner(RGWUser *user) = 0;
110
111 const std::string& get_name() const { return ent.bucket.name; }
112 const std::string& get_tenant() const { return ent.bucket.tenant; }
113 const std::string& get_marker() const { return ent.bucket.marker; }
114 const std::string& get_bucket_id() const { return ent.bucket.bucket_id; }
115 size_t get_size() const { return ent.size; }
116 size_t get_size_rounded() const { return ent.size_rounded; }
117 uint64_t get_count() const { return ent.count; }
118 rgw_placement_rule get_placement_rule() const { return ent.placement_rule; }
119 ceph::real_time& get_creation_time() { return ent.creation_time; };
120
121 void convert(cls_user_bucket_entry *b) const {
122 ent.convert(b);
123 }
124
125 /* dang - This is temporary, until the API is completed */
126 rgw_bucket& get_bi() { return ent.bucket; }
127 RGWBucketInfo& get_info() { return info; }
128
129 friend inline ostream& operator<<(ostream& out, const RGWBucket& b) {
130 out << b.ent.bucket;
131 return out;
132 }
133
134
135 friend class RGWBucketList;
136 protected:
137 virtual void set_ent(RGWBucketEnt& _ent) { ent = _ent; }
138 };
139
140 class RGWBucketList {
141 std::map<std::string, RGWBucket*> buckets;
142 bool truncated;
143
144 public:
145 RGWBucketList() : buckets(), truncated(false) {}
146 RGWBucketList(RGWBucketList&&) = default;
147 RGWBucketList& operator=(const RGWBucketList&) = default;
148 ~RGWBucketList();
149
150 map<string, RGWBucket*>& get_buckets() { return buckets; }
151 bool is_truncated(void) const { return truncated; }
152 void set_truncated(bool trunc) { truncated = trunc; }
153 void add(RGWBucket* bucket) {
154 buckets[bucket->ent.bucket.name] = bucket;
155 }
156 size_t count() const { return buckets.size(); }
157 void clear() { buckets.clear(); truncated = false; }
158 }; // class RGWBucketList
159
160 class RGWObject {
161 protected:
162 rgw_obj_key key;
163
164 public:
165 RGWObject() : key() {}
166 RGWObject(const rgw_obj_key& _k) : key(_k) {}
167 virtual ~RGWObject() = default;
168
169 virtual int read(off_t offset, off_t length, std::iostream& stream) = 0;
170 virtual int write(off_t offset, off_t length, std::iostream& stream) = 0;
171 virtual RGWAttrs& get_attrs(void) = 0;
172 virtual int set_attrs(RGWAttrs& attrs) = 0;
173 virtual int delete_object(void) = 0;
174 virtual RGWAccessControlPolicy& get_acl(void) = 0;
175 virtual int set_acl(const RGWAccessControlPolicy& acl) = 0;
176 };
177
178
179 class RGWRadosStore;
180
181 class RGWRadosUser : public RGWUser {
182 private:
183 RGWRadosStore *store;
184
185 public:
186 RGWRadosUser(RGWRadosStore *_st, const rgw_user& _u) : RGWUser(_u), store(_st) { }
187 RGWRadosUser(RGWRadosStore *_st, const RGWUserInfo& _i) : RGWUser(_i), store(_st) { }
188 RGWRadosUser(RGWRadosStore *_st) : store(_st) { }
189 RGWRadosUser() {}
190
191 int list_buckets(const string& marker, const string& end_marker,
192 uint64_t max, bool need_stats, RGWBucketList& buckets);
193 RGWBucket* add_bucket(rgw_bucket& bucket, ceph::real_time creation_time);
194
195 /* Placeholders */
196 int get_by_id(rgw_user id, optional_yield y);
197
198 friend class RGWRadosBucket;
199 };
200
201 class RGWRadosObject : public RGWObject {
202 private:
203 RGWRadosStore *store;
204 RGWAttrs attrs;
205 RGWAccessControlPolicy acls;
206
207 public:
208 RGWRadosObject()
209 : attrs(),
210 acls() {
211 }
212
213 RGWRadosObject(RGWRadosStore *_st, const rgw_obj_key& _k)
214 : RGWObject(_k),
215 store(_st),
216 attrs(),
217 acls() {
218 }
219
220 int read(off_t offset, off_t length, std::iostream& stream) { return length; }
221 int write(off_t offset, off_t length, std::iostream& stream) { return length; }
222 RGWAttrs& get_attrs(void) { return attrs; }
223 int set_attrs(RGWAttrs& a) { attrs = a; return 0; }
224 int delete_object(void) { return 0; }
225 RGWAccessControlPolicy& get_acl(void) { return acls; }
226 int set_acl(const RGWAccessControlPolicy& acl) { acls = acl; return 0; }
227 };
228
229 class RGWRadosBucket : public RGWBucket {
230 private:
231 RGWRadosStore *store;
232 RGWRadosObject *object;
233 RGWAccessControlPolicy acls;
234 RGWRadosUser user;
235
236 public:
237 RGWRadosBucket()
238 : store(nullptr),
239 object(nullptr),
240 acls(),
241 user() {
242 }
243
244 RGWRadosBucket(RGWRadosStore *_st, RGWUser& _u, const rgw_bucket& _b)
245 : RGWBucket(_b),
246 store(_st),
247 object(nullptr),
248 acls(),
249 user(dynamic_cast<RGWRadosUser&>(_u)) {
250 }
251
252 RGWRadosBucket(RGWRadosStore *_st, RGWUser& _u, const RGWBucketEnt& _e)
253 : RGWBucket(_e),
254 store(_st),
255 object(nullptr),
256 acls(),
257 user(dynamic_cast<RGWRadosUser&>(_u)) {
258 }
259
260 ~RGWRadosBucket() { }
261
262 RGWObject* get_object(const rgw_obj_key& key) { return object; }
263 RGWBucketList* list(void) { return new RGWBucketList(); }
264 RGWObject* create_object(const rgw_obj_key& key /* Attributes */) override;
265 virtual int remove_bucket(bool delete_children, optional_yield y) override;
266 RGWAccessControlPolicy& get_acl(void) { return acls; }
267 virtual int set_acl(RGWAccessControlPolicy& acl, optional_yield y) override;
268 virtual int get_bucket_info(optional_yield y) override;
269 virtual int get_bucket_stats(RGWBucketInfo& bucket_info, int shard_id,
270 std::string *bucket_ver, std::string *master_ver,
271 std::map<RGWObjCategory, RGWStorageStats>& stats,
272 std::string *max_marker = nullptr,
273 bool *syncstopped = nullptr) override;
274 virtual int read_bucket_stats(optional_yield y) override;
275 virtual int sync_user_stats() override;
276 virtual int update_container_stats(void) override;
277 virtual int check_bucket_shards(void) override;
278 virtual int link(RGWUser* new_user, optional_yield y) override;
279 virtual int unlink(RGWUser* new_user, optional_yield y) override;
280 virtual int chown(RGWUser* new_user, RGWUser* old_user, optional_yield y) override;
281 virtual bool is_owner(RGWUser *user) override;
282 };
283
284 class RGWRadosStore : public RGWStore {
285 private:
286 RGWRados *rados;
287 RGWUserCtl *user_ctl;
288
289 public:
290 RGWRadosStore()
291 : rados(nullptr) {
292 }
293 ~RGWRadosStore() {
294 delete rados;
295 }
296
297 virtual RGWUser* get_user(const rgw_user& u);
298 virtual int get_bucket(RGWUser& u, const rgw_bucket& b, RGWBucket** bucket) override;
299 //virtual RGWBucket* create_bucket(RGWUser& u, const rgw_bucket& b);
300 virtual RGWBucketList* list_buckets(void) { return new RGWBucketList(); }
301
302 void setRados(RGWRados * st) { rados = st; }
303 RGWRados *getRados(void) { return rados; }
304
305 RGWServices *svc() { return &rados->svc; }
306 RGWCtl *ctl() { return &rados->ctl; }
307
308 void setUserCtl(RGWUserCtl *_ctl) { user_ctl = _ctl; }
309
310 void finalize(void) override;
311
312 virtual CephContext *ctx(void) { return rados->ctx(); }
313 };
314
315 } } // namespace rgw::sal
316
317
318 class RGWStoreManager {
319 public:
320 RGWStoreManager() {}
321 static rgw::sal::RGWRadosStore *get_storage(CephContext *cct, bool use_gc_thread, bool use_lc_thread, bool quota_threads,
322 bool run_sync_thread, bool run_reshard_thread, bool use_cache = true) {
323 rgw::sal::RGWRadosStore *store = init_storage_provider(cct, use_gc_thread, use_lc_thread,
324 quota_threads, run_sync_thread, run_reshard_thread, use_cache);
325 return store;
326 }
327 static rgw::sal::RGWRadosStore *get_raw_storage(CephContext *cct) {
328 rgw::sal::RGWRadosStore *rados = init_raw_storage_provider(cct);
329 return rados;
330 }
331 static rgw::sal::RGWRadosStore *init_storage_provider(CephContext *cct, bool use_gc_thread, bool use_lc_thread, bool quota_threads, bool run_sync_thread, bool run_reshard_thread, bool use_metadata_cache);
332 static rgw::sal::RGWRadosStore *init_raw_storage_provider(CephContext *cct);
333 static void close_storage(rgw::sal::RGWRadosStore *store);
334
335 };