1 #ifndef CEPH_RGW_SERVICES_RADOS_H
2 #define CEPH_RGW_SERVICES_RADOS_H
5 #include "rgw/rgw_service.h"
7 #include "include/rados/librados.hpp"
8 #include "common/async/yield_context.h"
10 class RGWAccessListFilter
{
12 virtual ~RGWAccessListFilter() {}
13 virtual bool filter(const string
& name
, string
& key
) = 0;
16 struct RGWAccessListFilterPrefix
: public RGWAccessListFilter
{
19 explicit RGWAccessListFilterPrefix(const string
& _prefix
) : prefix(_prefix
) {}
20 bool filter(const string
& name
, string
& key
) override
{
21 return (prefix
.compare(key
.substr(0, prefix
.size())) == 0);
25 struct rgw_rados_ref
{
27 librados::IoCtx ioctx
;
30 class RGWSI_RADOS
: public RGWServiceInstance
32 std::vector
<librados::Rados
> rados
;
33 uint32_t next_rados_handle
{0};
35 std::map
<pthread_t
, int> rados_map
;
37 int do_start() override
;
39 librados::Rados
* get_rados_handle(int rados_handle
);
40 int open_pool_ctx(const rgw_pool
& pool
, librados::IoCtx
& io_ctx
, int rados_handle
);
41 int pool_iterate(librados::IoCtx
& ioctx
,
42 librados::NObjectIterator
& iter
,
43 uint32_t num
, vector
<rgw_bucket_dir_entry
>& objs
,
44 RGWAccessListFilter
*filter
,
48 RGWSI_RADOS(CephContext
*cct
): RGWServiceInstance(cct
),
49 handle_lock("rados_handle_lock") {}
53 uint64_t instance_id();
58 friend class RGWSI_RADOS
;
61 RGWSI_RADOS
*rados_svc
{nullptr};
65 void init(const rgw_raw_obj
& obj
);
67 Obj(RGWSI_RADOS
*_rados_svc
, const rgw_raw_obj
& _obj
, int _rados_handle
) : rados_svc(_rados_svc
), rados_handle(_rados_handle
) {
76 int operate(librados::ObjectWriteOperation
*op
, optional_yield y
);
77 int operate(librados::ObjectReadOperation
*op
, bufferlist
*pbl
,
79 int aio_operate(librados::AioCompletion
*c
, librados::ObjectWriteOperation
*op
);
80 int aio_operate(librados::AioCompletion
*c
, librados::ObjectReadOperation
*op
,
83 int watch(uint64_t *handle
, librados::WatchCtx2
*ctx
);
84 int aio_watch(librados::AioCompletion
*c
, uint64_t *handle
, librados::WatchCtx2
*ctx
);
85 int unwatch(uint64_t handle
);
86 int notify(bufferlist
& bl
,
89 void notify_ack(uint64_t notify_id
,
93 uint64_t get_last_version();
95 rgw_rados_ref
& get_ref() { return ref
; }
96 const rgw_rados_ref
& get_ref() const { return ref
; }
100 friend class RGWSI_RADOS
;
103 RGWSI_RADOS
*rados_svc
{nullptr};
104 int rados_handle
{-1};
107 Pool(RGWSI_RADOS
*_rados_svc
,
108 const rgw_pool
& _pool
,
109 int _rados_handle
) : rados_svc(_rados_svc
),
110 rados_handle(_rados_handle
),
113 Pool(RGWSI_RADOS
*_rados_svc
) : rados_svc(_rados_svc
) {}
118 int create(const std::vector
<rgw_pool
>& pools
, std::vector
<int> *retcodes
);
125 bool initialized
{false};
126 librados::IoCtx ioctx
;
127 librados::NObjectIterator iter
;
128 RGWAccessListFilter
*filter
{nullptr};
131 List(Pool
& _pool
) : pool(_pool
) {}
133 int init(const string
& marker
, RGWAccessListFilter
*filter
= nullptr);
134 int get_next(int max
,
135 std::list
<string
> *oids
,
147 friend class RGWSI_RADOS
;
149 RGWSI_RADOS
*rados_svc
{nullptr};
150 int rados_handle
{-1};
152 Handle(RGWSI_RADOS
*_rados_svc
, int _rados_handle
) : rados_svc(_rados_svc
),
153 rados_handle(_rados_handle
) {}
155 Obj
obj(const rgw_raw_obj
& o
) {
156 return Obj(rados_svc
, o
, rados_handle
);
159 Pool
pool(const rgw_pool
& p
) {
160 return Pool(rados_svc
, p
, rados_handle
);
166 Handle
handle(int rados_handle
) {
167 return Handle(this, rados_handle
);
170 Obj
obj(const rgw_raw_obj
& o
) {
171 return Obj(this, o
, -1);
178 Pool
pool(const rgw_pool
& p
) {
179 return Pool(this, p
, -1);
184 friend class Pool::List
;