]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_rados.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rgw / services / svc_rados.h
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
10 class RGWAccessListFilter {
11 public:
12 virtual ~RGWAccessListFilter() {}
13 virtual bool filter(const string& name, string& key) = 0;
14 };
15
16 struct 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
25 struct rgw_rados_ref {
26 rgw_raw_obj obj;
27 librados::IoCtx ioctx;
28 };
29
30 class RGWSI_RADOS : public RGWServiceInstance
31 {
32 std::vector<librados::Rados> rados;
33 uint32_t next_rados_handle{0};
34 RWLock handle_lock;
35 std::map<pthread_t, int> rados_map;
36
37 int do_start() override;
38
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,
45 bool *is_truncated);
46
47 public:
48 RGWSI_RADOS(CephContext *cct): RGWServiceInstance(cct),
49 handle_lock("rados_handle_lock") {}
50
51 void init() {}
52
53 uint64_t instance_id();
54
55 class Handle;
56
57 class Obj {
58 friend class RGWSI_RADOS;
59 friend class Handle;
60
61 RGWSI_RADOS *rados_svc{nullptr};
62 int rados_handle{-1};
63 rgw_rados_ref ref;
64
65 void init(const rgw_raw_obj& obj);
66
67 Obj(RGWSI_RADOS *_rados_svc, const rgw_raw_obj& _obj, int _rados_handle) : rados_svc(_rados_svc), rados_handle(_rados_handle) {
68 init(_obj);
69 }
70
71 public:
72 Obj() {}
73
74 int open();
75
76 int operate(librados::ObjectWriteOperation *op, optional_yield y);
77 int operate(librados::ObjectReadOperation *op, bufferlist *pbl,
78 optional_yield y);
79 int aio_operate(librados::AioCompletion *c, librados::ObjectWriteOperation *op);
80 int aio_operate(librados::AioCompletion *c, librados::ObjectReadOperation *op,
81 bufferlist *pbl);
82
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,
87 uint64_t timeout_ms,
88 bufferlist *pbl);
89 void notify_ack(uint64_t notify_id,
90 uint64_t cookie,
91 bufferlist& bl);
92
93 uint64_t get_last_version();
94
95 rgw_rados_ref& get_ref() { return ref; }
96 const rgw_rados_ref& get_ref() const { return ref; }
97 };
98
99 class Pool {
100 friend class RGWSI_RADOS;
101 friend class Handle;
102
103 RGWSI_RADOS *rados_svc{nullptr};
104 int rados_handle{-1};
105 rgw_pool pool;
106
107 Pool(RGWSI_RADOS *_rados_svc,
108 const rgw_pool& _pool,
109 int _rados_handle) : rados_svc(_rados_svc),
110 rados_handle(_rados_handle),
111 pool(_pool) {}
112
113 Pool(RGWSI_RADOS *_rados_svc) : rados_svc(_rados_svc) {}
114 public:
115 Pool() {}
116
117 int create();
118 int create(const std::vector<rgw_pool>& pools, std::vector<int> *retcodes);
119 int lookup();
120
121 struct List {
122 Pool& pool;
123
124 struct Ctx {
125 bool initialized{false};
126 librados::IoCtx ioctx;
127 librados::NObjectIterator iter;
128 RGWAccessListFilter *filter{nullptr};
129 } ctx;
130
131 List(Pool& _pool) : pool(_pool) {}
132
133 int init(const string& marker, RGWAccessListFilter *filter = nullptr);
134 int get_next(int max,
135 std::list<string> *oids,
136 bool *is_truncated);
137 };
138
139 List op() {
140 return List(*this);
141 }
142
143 friend class List;
144 };
145
146 class Handle {
147 friend class RGWSI_RADOS;
148
149 RGWSI_RADOS *rados_svc{nullptr};
150 int rados_handle{-1};
151
152 Handle(RGWSI_RADOS *_rados_svc, int _rados_handle) : rados_svc(_rados_svc),
153 rados_handle(_rados_handle) {}
154 public:
155 Obj obj(const rgw_raw_obj& o) {
156 return Obj(rados_svc, o, rados_handle);
157 }
158
159 Pool pool(const rgw_pool& p) {
160 return Pool(rados_svc, p, rados_handle);
161 }
162
163 int watch_flush();
164 };
165
166 Handle handle(int rados_handle) {
167 return Handle(this, rados_handle);
168 }
169
170 Obj obj(const rgw_raw_obj& o) {
171 return Obj(this, o, -1);
172 }
173
174 Pool pool() {
175 return Pool(this);
176 }
177
178 Pool pool(const rgw_pool& p) {
179 return Pool(this, p, -1);
180 }
181
182 friend class Obj;
183 friend class Pool;
184 friend class Pool::List;
185 };
186
187 #endif