]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/services/svc_rados.h
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rgw / services / svc_rados.h
CommitLineData
11fdf7f2
TL
1#ifndef CEPH_RGW_SERVICES_RADOS_H
2#define CEPH_RGW_SERVICES_RADOS_H
3
4
5#include "rgw/rgw_service.h"
6
7#include "include/rados/librados.hpp"
8#include "common/async/yield_context.h"
9
10class RGWAccessListFilter {
11public:
12 virtual ~RGWAccessListFilter() {}
13 virtual bool filter(const string& name, string& key) = 0;
14};
15
16struct RGWAccessListFilterPrefix : public RGWAccessListFilter {
17 string prefix;
18
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);
22 }
23};
24
25struct rgw_rados_ref {
26 rgw_raw_obj obj;
27 librados::IoCtx ioctx;
28};
29
30class RGWSI_RADOS : public RGWServiceInstance
31{
494da23a 32 librados::Rados rados;
11fdf7f2
TL
33
34 int do_start() override;
35
494da23a
TL
36 librados::Rados* get_rados_handle();
37 int open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx);
11fdf7f2
TL
38 int pool_iterate(librados::IoCtx& ioctx,
39 librados::NObjectIterator& iter,
40 uint32_t num, vector<rgw_bucket_dir_entry>& objs,
41 RGWAccessListFilter *filter,
42 bool *is_truncated);
43
44public:
494da23a 45 RGWSI_RADOS(CephContext *cct) : RGWServiceInstance(cct) {}
11fdf7f2
TL
46
47 void init() {}
48
49 uint64_t instance_id();
50
51 class Handle;
52
53 class Obj {
54 friend class RGWSI_RADOS;
494da23a 55 friend Handle;
11fdf7f2
TL
56
57 RGWSI_RADOS *rados_svc{nullptr};
11fdf7f2
TL
58 rgw_rados_ref ref;
59
60 void init(const rgw_raw_obj& obj);
61
494da23a
TL
62 Obj(RGWSI_RADOS *_rados_svc, const rgw_raw_obj& _obj)
63 : rados_svc(_rados_svc) {
11fdf7f2
TL
64 init(_obj);
65 }
66
67 public:
68 Obj() {}
69
70 int open();
71
72 int operate(librados::ObjectWriteOperation *op, optional_yield y);
73 int operate(librados::ObjectReadOperation *op, bufferlist *pbl,
74 optional_yield y);
75 int aio_operate(librados::AioCompletion *c, librados::ObjectWriteOperation *op);
76 int aio_operate(librados::AioCompletion *c, librados::ObjectReadOperation *op,
77 bufferlist *pbl);
78
79 int watch(uint64_t *handle, librados::WatchCtx2 *ctx);
80 int aio_watch(librados::AioCompletion *c, uint64_t *handle, librados::WatchCtx2 *ctx);
81 int unwatch(uint64_t handle);
82 int notify(bufferlist& bl,
83 uint64_t timeout_ms,
84 bufferlist *pbl);
85 void notify_ack(uint64_t notify_id,
86 uint64_t cookie,
87 bufferlist& bl);
88
89 uint64_t get_last_version();
90
91 rgw_rados_ref& get_ref() { return ref; }
92 const rgw_rados_ref& get_ref() const { return ref; }
93 };
94
95 class Pool {
96 friend class RGWSI_RADOS;
494da23a 97 friend Handle;
11fdf7f2
TL
98
99 RGWSI_RADOS *rados_svc{nullptr};
11fdf7f2
TL
100 rgw_pool pool;
101
102 Pool(RGWSI_RADOS *_rados_svc,
494da23a
TL
103 const rgw_pool& _pool) : rados_svc(_rados_svc),
104 pool(_pool) {}
11fdf7f2
TL
105
106 Pool(RGWSI_RADOS *_rados_svc) : rados_svc(_rados_svc) {}
107 public:
108 Pool() {}
109
110 int create();
111 int create(const std::vector<rgw_pool>& pools, std::vector<int> *retcodes);
112 int lookup();
113
114 struct List {
115 Pool& pool;
116
117 struct Ctx {
118 bool initialized{false};
119 librados::IoCtx ioctx;
120 librados::NObjectIterator iter;
121 RGWAccessListFilter *filter{nullptr};
122 } ctx;
123
124 List(Pool& _pool) : pool(_pool) {}
125
126 int init(const string& marker, RGWAccessListFilter *filter = nullptr);
127 int get_next(int max,
128 std::list<string> *oids,
129 bool *is_truncated);
130 };
131
132 List op() {
133 return List(*this);
134 }
135
494da23a 136 friend List;
11fdf7f2
TL
137 };
138
139 class Handle {
140 friend class RGWSI_RADOS;
141
142 RGWSI_RADOS *rados_svc{nullptr};
11fdf7f2 143
494da23a 144 Handle(RGWSI_RADOS *_rados_svc) : rados_svc(_rados_svc) {}
11fdf7f2
TL
145 public:
146 Obj obj(const rgw_raw_obj& o) {
494da23a 147 return Obj(rados_svc, o);
11fdf7f2
TL
148 }
149
150 Pool pool(const rgw_pool& p) {
494da23a 151 return Pool(rados_svc, p);
11fdf7f2
TL
152 }
153
154 int watch_flush();
155 };
156
494da23a
TL
157 Handle handle() {
158 return Handle(this);
11fdf7f2
TL
159 }
160
161 Obj obj(const rgw_raw_obj& o) {
494da23a 162 return Obj(this, o);
11fdf7f2
TL
163 }
164
165 Pool pool() {
166 return Pool(this);
167 }
168
169 Pool pool(const rgw_pool& p) {
494da23a 170 return Pool(this, p);
11fdf7f2
TL
171 }
172
494da23a
TL
173 friend Obj;
174 friend Pool;
175 friend Pool::List;
11fdf7f2
TL
176};
177
178#endif