1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
6 #include "rgw/rgw_service.h"
8 #include "include/rados/librados.hpp"
9 #include "common/async/yield_context.h"
10 #include "common/RWLock.h"
12 class RGWAsyncRadosProcessor
;
14 class RGWAccessListFilter
{
16 virtual ~RGWAccessListFilter() {}
17 virtual bool filter(const string
& name
, string
& key
) = 0;
20 struct RGWAccessListFilterPrefix
: public RGWAccessListFilter
{
23 explicit RGWAccessListFilterPrefix(const string
& _prefix
) : prefix(_prefix
) {}
24 bool filter(const string
& name
, string
& key
) override
{
25 return (prefix
.compare(key
.substr(0, prefix
.size())) == 0);
29 class RGWSI_RADOS
: public RGWServiceInstance
31 librados::Rados rados
;
32 std::unique_ptr
<RGWAsyncRadosProcessor
> async_processor
;
34 int do_start(optional_yield
) override
;
39 bool mostly_omap
{false};
43 OpenParams
& set_create(bool _create
) {
47 OpenParams
& set_mostly_omap(bool _mostly_omap
) {
48 mostly_omap
= _mostly_omap
;
54 int open_pool_ctx(const rgw_pool
& pool
, librados::IoCtx
& io_ctx
,
55 const OpenParams
& params
= {});
56 int pool_iterate(librados::IoCtx
& ioctx
,
57 librados::NObjectIterator
& iter
,
58 uint32_t num
, vector
<rgw_bucket_dir_entry
>& objs
,
59 RGWAccessListFilter
*filter
,
63 RGWSI_RADOS(CephContext
*cct
);
65 librados::Rados
* get_rados_handle();
68 void shutdown() override
;
70 uint64_t instance_id();
71 bool check_secure_mon_conn() const;
73 RGWAsyncRadosProcessor
*get_async_processor() {
74 return async_processor
.get();
77 int clog_warn(const string
& msg
);
82 friend class RGWSI_RADOS
;
86 RGWSI_RADOS
*rados_svc
{nullptr};
90 librados::IoCtx ioctx
;
93 Pool(RGWSI_RADOS
*_rados_svc
,
94 const rgw_pool
& _pool
) : rados_svc(_rados_svc
),
97 Pool(RGWSI_RADOS
*_rados_svc
) : rados_svc(_rados_svc
) {}
102 int create(const std::vector
<rgw_pool
>& pools
, std::vector
<int> *retcodes
);
104 int open(const OpenParams
& params
= {});
106 const rgw_pool
& get_pool() {
110 librados::IoCtx
& ioctx() {
118 bool initialized
{false};
119 librados::IoCtx ioctx
;
120 librados::NObjectIterator iter
;
121 RGWAccessListFilter
*filter
{nullptr};
125 List(Pool
*_pool
) : pool(_pool
) {}
127 int init(const string
& marker
, RGWAccessListFilter
*filter
= nullptr);
128 int get_next(int max
,
129 std::vector
<string
> *oids
,
132 int get_marker(string
*marker
);
144 RGWSI_RADOS::Pool pool
;
149 friend class RGWSI_RADOS
;
152 RGWSI_RADOS
*rados_svc
{nullptr};
155 void init(const rgw_raw_obj
& obj
);
157 Obj(RGWSI_RADOS
*_rados_svc
, const rgw_raw_obj
& _obj
)
158 : rados_svc(_rados_svc
) {
162 Obj(Pool
& pool
, const string
& oid
);
169 int operate(librados::ObjectWriteOperation
*op
, optional_yield y
,
171 int operate(librados::ObjectReadOperation
*op
, bufferlist
*pbl
,
172 optional_yield y
, int flags
= 0);
173 int aio_operate(librados::AioCompletion
*c
, librados::ObjectWriteOperation
*op
);
174 int aio_operate(librados::AioCompletion
*c
, librados::ObjectReadOperation
*op
,
177 int watch(uint64_t *handle
, librados::WatchCtx2
*ctx
);
178 int aio_watch(librados::AioCompletion
*c
, uint64_t *handle
, librados::WatchCtx2
*ctx
);
179 int unwatch(uint64_t handle
);
180 int notify(bufferlist
& bl
, uint64_t timeout_ms
,
181 bufferlist
*pbl
, optional_yield y
);
182 void notify_ack(uint64_t notify_id
,
186 uint64_t get_last_version();
188 rados_ref
& get_ref() { return ref
; }
189 const rados_ref
& get_ref() const { return ref
; }
191 const rgw_raw_obj
& get_raw_obj() const {
197 friend class RGWSI_RADOS
;
199 RGWSI_RADOS
*rados_svc
{nullptr};
201 Handle(RGWSI_RADOS
*_rados_svc
) : rados_svc(_rados_svc
) {}
203 Obj
obj(const rgw_raw_obj
& o
);
205 Pool
pool(const rgw_pool
& p
) {
206 return Pool(rados_svc
, p
);
211 int mon_command(std::string cmd
,
212 const bufferlist
& inbl
,
221 Obj
obj(const rgw_raw_obj
& o
) {
225 Obj
obj(Pool
& pool
, const string
& oid
) {
226 return Obj(pool
, oid
);
233 Pool
pool(const rgw_pool
& p
) {
234 return Pool(this, p
);
242 using rgw_rados_ref
= RGWSI_RADOS::rados_ref
;
244 inline ostream
& operator<<(ostream
& out
, const RGWSI_RADOS::Obj
& obj
) {
245 return out
<< obj
.get_raw_obj();