1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2019 Red Hat, Inc.
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.
18 #include "rgw_rados.h"
21 namespace rgw
{ namespace sal
{
23 #define RGW_SAL_VERSION 1
30 typedef std::map
<std::string
, ceph::bufferlist
> RGWAttrs
;
35 virtual ~RGWStore() = default;
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;
42 virtual void finalize(void)=0;
44 virtual CephContext
*ctx(void)=0;
53 RGWUser(const rgw_user
& _u
) : info() { info
.user_id
= _u
; }
54 RGWUser(const RGWUserInfo
& _i
) : info(_i
) {}
55 virtual ~RGWUser() = default;
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
; }
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
; }
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
; }
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;
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;
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
; };
121 void convert(cls_user_bucket_entry
*b
) const {
125 /* dang - This is temporary, until the API is completed */
126 rgw_bucket
& get_bi() { return ent
.bucket
; }
127 RGWBucketInfo
& get_info() { return info
; }
129 friend inline ostream
& operator<<(ostream
& out
, const RGWBucket
& b
) {
135 friend class RGWBucketList
;
137 virtual void set_ent(RGWBucketEnt
& _ent
) { ent
= _ent
; }
140 class RGWBucketList
{
141 std::map
<std::string
, RGWBucket
*> buckets
;
145 RGWBucketList() : buckets(), truncated(false) {}
146 RGWBucketList(RGWBucketList
&&) = default;
147 RGWBucketList
& operator=(const RGWBucketList
&) = default;
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
;
156 size_t count() const { return buckets
.size(); }
157 void clear() { buckets
.clear(); truncated
= false; }
158 }; // class RGWBucketList
165 RGWObject() : key() {}
166 RGWObject(const rgw_obj_key
& _k
) : key(_k
) {}
167 virtual ~RGWObject() = default;
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;
181 class RGWRadosUser
: public RGWUser
{
183 RGWRadosStore
*store
;
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
) { }
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
);
196 int get_by_id(rgw_user id
, optional_yield y
);
198 friend class RGWRadosBucket
;
201 class RGWRadosObject
: public RGWObject
{
203 RGWRadosStore
*store
;
205 RGWAccessControlPolicy acls
;
213 RGWRadosObject(RGWRadosStore
*_st
, const rgw_obj_key
& _k
)
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; }
229 class RGWRadosBucket
: public RGWBucket
{
231 RGWRadosStore
*store
;
232 RGWRadosObject
*object
;
233 RGWAccessControlPolicy acls
;
244 RGWRadosBucket(RGWRadosStore
*_st
, RGWUser
& _u
, const rgw_bucket
& _b
)
249 user(dynamic_cast<RGWRadosUser
&>(_u
)) {
252 RGWRadosBucket(RGWRadosStore
*_st
, RGWUser
& _u
, const RGWBucketEnt
& _e
)
257 user(dynamic_cast<RGWRadosUser
&>(_u
)) {
260 ~RGWRadosBucket() { }
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
;
284 class RGWRadosStore
: public RGWStore
{
287 RGWUserCtl
*user_ctl
;
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(); }
302 void setRados(RGWRados
* st
) { rados
= st
; }
303 RGWRados
*getRados(void) { return rados
; }
305 RGWServices
*svc() { return &rados
->svc
; }
306 RGWCtl
*ctl() { return &rados
->ctl
; }
308 void setUserCtl(RGWUserCtl
*_ctl
) { user_ctl
= _ctl
; }
310 void finalize(void) override
;
312 virtual CephContext
*ctx(void) { return rados
->ctx(); }
315 } } // namespace rgw::sal
318 class 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
);
327 static rgw::sal::RGWRadosStore
*get_raw_storage(CephContext
*cct
) {
328 rgw::sal::RGWRadosStore
*rados
= init_raw_storage_provider(cct
);
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
);