]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef __LIBRADOS_HPP |
2 | #define __LIBRADOS_HPP | |
3 | ||
7c673cae FG |
4 | #include <string> |
5 | #include <list> | |
6 | #include <map> | |
11fdf7f2 | 7 | #include <memory> |
7c673cae FG |
8 | #include <set> |
9 | #include <vector> | |
10 | #include <utility> | |
7c673cae FG |
11 | #include "buffer.h" |
12 | ||
13 | #include "librados.h" | |
11fdf7f2 | 14 | #include "librados_fwd.hpp" |
7c673cae FG |
15 | #include "rados_types.hpp" |
16 | ||
17 | namespace libradosstriper | |
18 | { | |
19 | class RadosStriper; | |
20 | } | |
21 | ||
11fdf7f2 | 22 | namespace librados { |
7c673cae | 23 | |
11fdf7f2 TL |
24 | using ceph::bufferlist; |
25 | ||
26 | struct AioCompletionImpl; | |
27 | struct IoCtxImpl; | |
28 | struct ListObjectImpl; | |
29 | class NObjectIteratorImpl; | |
30 | struct ObjListCtx; | |
31 | class ObjectOperationImpl; | |
32 | struct PlacementGroupImpl; | |
33 | struct PoolAsyncCompletionImpl; | |
7c673cae | 34 | |
11fdf7f2 TL |
35 | typedef struct rados_cluster_stat_t cluster_stat_t; |
36 | typedef struct rados_pool_stat_t pool_stat_t; | |
7c673cae | 37 | |
11fdf7f2 TL |
38 | typedef void *list_ctx_t; |
39 | typedef uint64_t auid_t; | |
40 | typedef void *config_t; | |
7c673cae | 41 | |
11fdf7f2 TL |
42 | typedef struct { |
43 | std::string client; | |
44 | std::string cookie; | |
45 | std::string address; | |
46 | } locker_t; | |
7c673cae | 47 | |
11fdf7f2 | 48 | typedef std::map<std::string, pool_stat_t> stats_map; |
7c673cae | 49 | |
11fdf7f2 TL |
50 | typedef void *completion_t; |
51 | typedef void (*callback_t)(completion_t cb, void *arg); | |
52 | ||
53 | inline namespace v14_2_0 { | |
54 | ||
55 | class IoCtx; | |
56 | class RadosClient; | |
7c673cae FG |
57 | |
58 | class CEPH_RADOS_API ListObject | |
59 | { | |
60 | public: | |
61 | const std::string& get_nspace() const; | |
62 | const std::string& get_oid() const; | |
63 | const std::string& get_locator() const; | |
64 | ||
65 | ListObject(); | |
66 | ~ListObject(); | |
67 | ListObject( const ListObject&); | |
68 | ListObject& operator=(const ListObject& rhs); | |
69 | private: | |
70 | ListObject(ListObjectImpl *impl); | |
71 | ||
11fdf7f2 | 72 | friend class librados::NObjectIteratorImpl; |
7c673cae FG |
73 | friend std::ostream& operator<<(std::ostream& out, const ListObject& lop); |
74 | ||
75 | ListObjectImpl *impl; | |
76 | }; | |
77 | CEPH_RADOS_API std::ostream& operator<<(std::ostream& out, const librados::ListObject& lop); | |
78 | ||
79 | class CEPH_RADOS_API NObjectIterator; | |
80 | ||
81 | class CEPH_RADOS_API ObjectCursor | |
82 | { | |
83 | public: | |
84 | ObjectCursor(); | |
85 | ObjectCursor(const ObjectCursor &rhs); | |
86 | explicit ObjectCursor(rados_object_list_cursor c); | |
87 | ~ObjectCursor(); | |
88 | ObjectCursor& operator=(const ObjectCursor& rhs); | |
89 | bool operator<(const ObjectCursor &rhs) const; | |
90 | bool operator==(const ObjectCursor &rhs) const; | |
91 | void set(rados_object_list_cursor c); | |
92 | ||
93 | friend class IoCtx; | |
11fdf7f2 | 94 | friend class librados::NObjectIteratorImpl; |
7c673cae FG |
95 | friend std::ostream& operator<<(std::ostream& os, const librados::ObjectCursor& oc); |
96 | ||
97 | std::string to_str() const; | |
98 | bool from_str(const std::string& s); | |
99 | ||
100 | protected: | |
101 | rados_object_list_cursor c_cursor; | |
102 | }; | |
103 | CEPH_RADOS_API std::ostream& operator<<(std::ostream& os, const librados::ObjectCursor& oc); | |
104 | ||
105 | class CEPH_RADOS_API NObjectIterator : public std::iterator <std::forward_iterator_tag, ListObject> { | |
106 | public: | |
107 | static const NObjectIterator __EndObjectIterator; | |
108 | NObjectIterator(): impl(NULL) {} | |
109 | ~NObjectIterator(); | |
110 | NObjectIterator(const NObjectIterator &rhs); | |
111 | NObjectIterator& operator=(const NObjectIterator& rhs); | |
112 | ||
113 | bool operator==(const NObjectIterator& rhs) const; | |
114 | bool operator!=(const NObjectIterator& rhs) const; | |
115 | const ListObject& operator*() const; | |
116 | const ListObject* operator->() const; | |
f64942e4 AA |
117 | NObjectIterator &operator++(); //< Preincrement; errors are thrown as exceptions |
118 | NObjectIterator operator++(int); //< Postincrement; errors are thrown as exceptions | |
7c673cae | 119 | friend class IoCtx; |
11fdf7f2 | 120 | friend class librados::NObjectIteratorImpl; |
7c673cae FG |
121 | |
122 | /// get current hash position of the iterator, rounded to the current pg | |
123 | uint32_t get_pg_hash_position() const; | |
124 | ||
f64942e4 AA |
125 | /// move the iterator to a given hash position. this may (will!) be rounded |
126 | /// to the nearest pg. errors are thrown as exceptions | |
7c673cae FG |
127 | uint32_t seek(uint32_t pos); |
128 | ||
f64942e4 | 129 | /// move the iterator to a given cursor position. errors are thrown as exceptions |
7c673cae FG |
130 | uint32_t seek(const ObjectCursor& cursor); |
131 | ||
132 | /// get current cursor position | |
133 | ObjectCursor get_cursor(); | |
134 | ||
135 | /** | |
136 | * Configure PGLS filter to be applied OSD-side (requires caller | |
137 | * to know/understand the format expected by the OSD) | |
138 | */ | |
139 | void set_filter(const bufferlist &bl); | |
140 | ||
141 | private: | |
142 | NObjectIterator(ObjListCtx *ctx_); | |
143 | void get_next(); | |
144 | NObjectIteratorImpl *impl; | |
145 | }; | |
146 | ||
147 | class CEPH_RADOS_API ObjectItem | |
148 | { | |
149 | public: | |
150 | std::string oid; | |
151 | std::string nspace; | |
152 | std::string locator; | |
153 | }; | |
154 | ||
155 | /// DEPRECATED; do not use | |
156 | class CEPH_RADOS_API WatchCtx { | |
157 | public: | |
158 | virtual ~WatchCtx(); | |
159 | virtual void notify(uint8_t opcode, uint64_t ver, bufferlist& bl) = 0; | |
160 | }; | |
161 | ||
162 | class CEPH_RADOS_API WatchCtx2 { | |
163 | public: | |
164 | virtual ~WatchCtx2(); | |
165 | /** | |
166 | * Callback activated when we receive a notify event. | |
167 | * | |
168 | * @param notify_id unique id for this notify event | |
169 | * @param cookie the watcher we are notifying | |
170 | * @param notifier_id the unique client id of the notifier | |
171 | * @param bl opaque notify payload (from the notifier) | |
172 | */ | |
173 | virtual void handle_notify(uint64_t notify_id, | |
174 | uint64_t cookie, | |
175 | uint64_t notifier_id, | |
176 | bufferlist& bl) = 0; | |
177 | ||
178 | /** | |
179 | * Callback activated when we encounter an error with the watch. | |
180 | * | |
181 | * Errors we may see: | |
182 | * -ENOTCONN : our watch was disconnected | |
183 | * -ETIMEDOUT : our watch is still valid, but we may have missed | |
184 | * a notify event. | |
185 | * | |
186 | * @param cookie the watcher with the problem | |
187 | * @param err error | |
188 | */ | |
189 | virtual void handle_error(uint64_t cookie, int err) = 0; | |
190 | }; | |
191 | ||
192 | struct CEPH_RADOS_API AioCompletion { | |
193 | AioCompletion(AioCompletionImpl *pc_) : pc(pc_) {} | |
9f95a23c | 194 | ~AioCompletion(); |
7c673cae | 195 | int set_complete_callback(void *cb_arg, callback_t cb); |
9f95a23c TL |
196 | int set_safe_callback(void *cb_arg, callback_t cb) |
197 | __attribute__ ((deprecated)); | |
7c673cae | 198 | int wait_for_complete(); |
9f95a23c | 199 | int wait_for_safe() __attribute__ ((deprecated)); |
7c673cae | 200 | int wait_for_complete_and_cb(); |
9f95a23c | 201 | int wait_for_safe_and_cb() __attribute__ ((deprecated)); |
7c673cae | 202 | bool is_complete(); |
9f95a23c | 203 | bool is_safe() __attribute__ ((deprecated)); |
7c673cae | 204 | bool is_complete_and_cb(); |
9f95a23c | 205 | bool is_safe_and_cb() __attribute__ ((deprecated)); |
7c673cae FG |
206 | int get_return_value(); |
207 | int get_version() __attribute__ ((deprecated)); | |
208 | uint64_t get_version64(); | |
209 | void release(); | |
210 | AioCompletionImpl *pc; | |
211 | }; | |
212 | ||
213 | struct CEPH_RADOS_API PoolAsyncCompletion { | |
214 | PoolAsyncCompletion(PoolAsyncCompletionImpl *pc_) : pc(pc_) {} | |
9f95a23c | 215 | ~PoolAsyncCompletion(); |
7c673cae FG |
216 | int set_callback(void *cb_arg, callback_t cb); |
217 | int wait(); | |
218 | bool is_complete(); | |
219 | int get_return_value(); | |
220 | void release(); | |
221 | PoolAsyncCompletionImpl *pc; | |
222 | }; | |
223 | ||
224 | /** | |
225 | * These are per-op flags which may be different among | |
226 | * ops added to an ObjectOperation. | |
227 | */ | |
228 | enum ObjectOperationFlags { | |
229 | OP_EXCL = LIBRADOS_OP_FLAG_EXCL, | |
230 | OP_FAILOK = LIBRADOS_OP_FLAG_FAILOK, | |
231 | OP_FADVISE_RANDOM = LIBRADOS_OP_FLAG_FADVISE_RANDOM, | |
232 | OP_FADVISE_SEQUENTIAL = LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL, | |
233 | OP_FADVISE_WILLNEED = LIBRADOS_OP_FLAG_FADVISE_WILLNEED, | |
234 | OP_FADVISE_DONTNEED = LIBRADOS_OP_FLAG_FADVISE_DONTNEED, | |
235 | OP_FADVISE_NOCACHE = LIBRADOS_OP_FLAG_FADVISE_NOCACHE, | |
236 | }; | |
237 | ||
238 | class CEPH_RADOS_API ObjectOperationCompletion { | |
239 | public: | |
240 | virtual ~ObjectOperationCompletion() {} | |
241 | virtual void handle_completion(int r, bufferlist& outbl) = 0; | |
242 | }; | |
243 | ||
244 | /** | |
245 | * These flags apply to the ObjectOperation as a whole. | |
246 | * | |
247 | * BALANCE_READS and LOCALIZE_READS should only be used | |
248 | * when reading from data you're certain won't change, | |
249 | * like a snapshot, or where eventual consistency is ok. | |
250 | * | |
251 | * ORDER_READS_WRITES will order reads the same way writes are | |
252 | * ordered (e.g., waiting for degraded objects). In particular, it | |
253 | * will make a write followed by a read sequence be preserved. | |
254 | * | |
255 | * IGNORE_CACHE will skip the caching logic on the OSD that normally | |
256 | * handles promotion of objects between tiers. This allows an operation | |
257 | * to operate (or read) the cached (or uncached) object, even if it is | |
258 | * not coherent. | |
259 | * | |
260 | * IGNORE_OVERLAY will ignore the pool overlay tiering metadata and | |
261 | * process the op directly on the destination pool. This is useful | |
262 | * for CACHE_FLUSH and CACHE_EVICT operations. | |
263 | */ | |
264 | enum ObjectOperationGlobalFlags { | |
265 | OPERATION_NOFLAG = LIBRADOS_OPERATION_NOFLAG, | |
266 | OPERATION_BALANCE_READS = LIBRADOS_OPERATION_BALANCE_READS, | |
267 | OPERATION_LOCALIZE_READS = LIBRADOS_OPERATION_LOCALIZE_READS, | |
268 | OPERATION_ORDER_READS_WRITES = LIBRADOS_OPERATION_ORDER_READS_WRITES, | |
269 | OPERATION_IGNORE_CACHE = LIBRADOS_OPERATION_IGNORE_CACHE, | |
270 | OPERATION_SKIPRWLOCKS = LIBRADOS_OPERATION_SKIPRWLOCKS, | |
271 | OPERATION_IGNORE_OVERLAY = LIBRADOS_OPERATION_IGNORE_OVERLAY, | |
272 | // send requests to cluster despite the cluster or pool being | |
273 | // marked full; ops will either succeed (e.g., delete) or return | |
274 | // EDQUOT or ENOSPC | |
275 | OPERATION_FULL_TRY = LIBRADOS_OPERATION_FULL_TRY, | |
9f95a23c | 276 | // mainly for delete |
7c673cae | 277 | OPERATION_FULL_FORCE = LIBRADOS_OPERATION_FULL_FORCE, |
31f18b77 | 278 | OPERATION_IGNORE_REDIRECT = LIBRADOS_OPERATION_IGNORE_REDIRECT, |
11fdf7f2 | 279 | OPERATION_ORDERSNAP = LIBRADOS_OPERATION_ORDERSNAP, |
9f95a23c TL |
280 | // enable/allow return value and per-op return code/buffers |
281 | OPERATION_RETURNVEC = LIBRADOS_OPERATION_RETURNVEC, | |
7c673cae FG |
282 | }; |
283 | ||
284 | /* | |
285 | * Alloc hint flags for the alloc_hint operation. | |
286 | */ | |
287 | enum AllocHintFlags { | |
288 | ALLOC_HINT_FLAG_SEQUENTIAL_WRITE = 1, | |
289 | ALLOC_HINT_FLAG_RANDOM_WRITE = 2, | |
290 | ALLOC_HINT_FLAG_SEQUENTIAL_READ = 4, | |
291 | ALLOC_HINT_FLAG_RANDOM_READ = 8, | |
292 | ALLOC_HINT_FLAG_APPEND_ONLY = 16, | |
293 | ALLOC_HINT_FLAG_IMMUTABLE = 32, | |
294 | ALLOC_HINT_FLAG_SHORTLIVED = 64, | |
295 | ALLOC_HINT_FLAG_LONGLIVED = 128, | |
296 | ALLOC_HINT_FLAG_COMPRESSIBLE = 256, | |
297 | ALLOC_HINT_FLAG_INCOMPRESSIBLE = 512, | |
298 | }; | |
299 | ||
300 | /* | |
301 | * ObjectOperation : compound object operation | |
302 | * Batch multiple object operations into a single request, to be applied | |
303 | * atomically. | |
304 | */ | |
305 | class CEPH_RADOS_API ObjectOperation | |
306 | { | |
307 | public: | |
308 | ObjectOperation(); | |
309 | virtual ~ObjectOperation(); | |
310 | ||
9f95a23c TL |
311 | ObjectOperation(const ObjectOperation&) = delete; |
312 | ObjectOperation& operator=(const ObjectOperation&) = delete; | |
313 | ||
314 | /** | |
315 | * Move constructor. | |
316 | * \warning A moved from ObjectOperation is invalid and may not be used for | |
317 | * any purpose. This is a hard contract violation and will | |
318 | * kill your program. | |
319 | */ | |
320 | ObjectOperation(ObjectOperation&&); | |
321 | ObjectOperation& operator =(ObjectOperation&&); | |
322 | ||
7c673cae FG |
323 | size_t size(); |
324 | void set_op_flags(ObjectOperationFlags flags) __attribute__((deprecated)); | |
325 | //flag mean ObjectOperationFlags | |
326 | void set_op_flags2(int flags); | |
327 | ||
11fdf7f2 | 328 | void cmpext(uint64_t off, const bufferlist& cmp_bl, int *prval); |
7c673cae FG |
329 | void cmpxattr(const char *name, uint8_t op, const bufferlist& val); |
330 | void cmpxattr(const char *name, uint8_t op, uint64_t v); | |
331 | void exec(const char *cls, const char *method, bufferlist& inbl); | |
332 | void exec(const char *cls, const char *method, bufferlist& inbl, bufferlist *obl, int *prval); | |
333 | void exec(const char *cls, const char *method, bufferlist& inbl, ObjectOperationCompletion *completion); | |
334 | /** | |
335 | * Guard operation with a check that object version == ver | |
336 | * | |
337 | * @param ver [in] version to check | |
338 | */ | |
339 | void assert_version(uint64_t ver); | |
340 | ||
341 | /** | |
11fdf7f2 | 342 | * Guard operation with a check that the object already exists |
7c673cae FG |
343 | */ |
344 | void assert_exists(); | |
345 | ||
346 | /** | |
347 | * get key/value pairs for specified keys | |
348 | * | |
349 | * @param assertions [in] comparison assertions | |
350 | * @param prval [out] place error code in prval upon completion | |
351 | * | |
352 | * assertions has the form of mappings from keys to (comparison rval, assertion) | |
353 | * The assertion field may be CEPH_OSD_CMPXATTR_OP_[GT|LT|EQ]. | |
354 | * | |
355 | * That is, to assert that the value at key 'foo' is greater than 'bar': | |
356 | * | |
357 | * ObjectReadOperation op; | |
358 | * int r; | |
359 | * map<string, pair<bufferlist, int> > assertions; | |
360 | * bufferlist bar(string('bar')); | |
361 | * assertions['foo'] = make_pair(bar, CEPH_OSD_CMP_XATTR_OP_GT); | |
362 | * op.omap_cmp(assertions, &r); | |
363 | */ | |
364 | void omap_cmp( | |
365 | const std::map<std::string, std::pair<bufferlist, int> > &assertions, | |
366 | int *prval); | |
367 | ||
368 | protected: | |
9f95a23c | 369 | ObjectOperationImpl* impl; |
7c673cae FG |
370 | friend class IoCtx; |
371 | friend class Rados; | |
372 | }; | |
373 | ||
374 | /* | |
375 | * ObjectWriteOperation : compound object write operation | |
376 | * Batch multiple object operations into a single request, to be applied | |
377 | * atomically. | |
378 | */ | |
379 | class CEPH_RADOS_API ObjectWriteOperation : public ObjectOperation | |
380 | { | |
381 | protected: | |
382 | time_t *unused; | |
383 | public: | |
384 | ObjectWriteOperation() : unused(NULL) {} | |
385 | ~ObjectWriteOperation() override {} | |
386 | ||
9f95a23c TL |
387 | ObjectWriteOperation(ObjectWriteOperation&&) = default; |
388 | ObjectWriteOperation& operator =(ObjectWriteOperation&&) = default; | |
389 | ||
7c673cae FG |
390 | void mtime(time_t *pt); |
391 | void mtime2(struct timespec *pts); | |
392 | ||
393 | void create(bool exclusive); | |
394 | void create(bool exclusive, | |
395 | const std::string& category); ///< NOTE: category is unused | |
396 | ||
397 | void write(uint64_t off, const bufferlist& bl); | |
398 | void write_full(const bufferlist& bl); | |
399 | void writesame(uint64_t off, uint64_t write_len, | |
400 | const bufferlist& bl); | |
401 | void append(const bufferlist& bl); | |
402 | void remove(); | |
403 | void truncate(uint64_t off); | |
404 | void zero(uint64_t off, uint64_t len); | |
405 | void rmxattr(const char *name); | |
406 | void setxattr(const char *name, const bufferlist& bl); | |
11fdf7f2 | 407 | void setxattr(const char *name, const bufferlist&& bl); |
7c673cae FG |
408 | void tmap_update(const bufferlist& cmdbl); |
409 | void tmap_put(const bufferlist& bl); | |
410 | void selfmanaged_snap_rollback(uint64_t snapid); | |
411 | ||
412 | /** | |
413 | * Rollback an object to the specified snapshot id | |
414 | * | |
415 | * Used with pool snapshots | |
416 | * | |
417 | * @param snapid [in] snopshot id specified | |
418 | */ | |
419 | void snap_rollback(uint64_t snapid); | |
420 | ||
421 | /** | |
422 | * set keys and values according to map | |
423 | * | |
424 | * @param map [in] keys and values to set | |
425 | */ | |
426 | void omap_set(const std::map<std::string, bufferlist> &map); | |
427 | ||
428 | /** | |
429 | * set header | |
430 | * | |
431 | * @param bl [in] header to set | |
432 | */ | |
433 | void omap_set_header(const bufferlist &bl); | |
434 | ||
435 | /** | |
436 | * Clears omap contents | |
437 | */ | |
438 | void omap_clear(); | |
439 | ||
440 | /** | |
441 | * Clears keys in to_rm | |
442 | * | |
443 | * @param to_rm [in] keys to remove | |
444 | */ | |
445 | void omap_rm_keys(const std::set<std::string> &to_rm); | |
446 | ||
447 | /** | |
448 | * Copy an object | |
449 | * | |
450 | * Copies an object from another location. The operation is atomic in that | |
451 | * the copy either succeeds in its entirety or fails (e.g., because the | |
452 | * source object was modified while the copy was in progress). | |
453 | * | |
454 | * @param src source object name | |
455 | * @param src_ioctx ioctx for the source object | |
456 | * @param src_version current version of the source object | |
457 | * @param src_fadvise_flags the fadvise flags for source object | |
458 | */ | |
459 | void copy_from(const std::string& src, const IoCtx& src_ioctx, | |
11fdf7f2 | 460 | uint64_t src_version, uint32_t src_fadvise_flags); |
7c673cae | 461 | |
9f95a23c TL |
462 | /** |
463 | * Copy an object | |
464 | * | |
465 | * Copies an object from another location. The operation is atomic in that | |
466 | * the copy either succeeds in its entirety or fails (e.g., because the | |
467 | * source object was modified while the copy was in progress). Instead of | |
468 | * copying truncate_seq and truncate_size from the source object it receives | |
469 | * these values as parameters. | |
470 | * | |
471 | * @param src source object name | |
472 | * @param src_ioctx ioctx for the source object | |
473 | * @param src_version current version of the source object | |
474 | * @param truncate_seq truncate sequence for the destination object | |
475 | * @param truncate_size truncate size for the destination object | |
476 | * @param src_fadvise_flags the fadvise flags for source object | |
477 | */ | |
478 | void copy_from2(const std::string& src, const IoCtx& src_ioctx, | |
479 | uint64_t src_version, uint32_t truncate_seq, | |
480 | uint64_t truncate_size, uint32_t src_fadvise_flags); | |
481 | ||
7c673cae FG |
482 | /** |
483 | * undirty an object | |
484 | * | |
485 | * Clear an objects dirty flag | |
486 | */ | |
487 | void undirty(); | |
488 | ||
489 | /** | |
490 | * Set allocation hint for an object | |
491 | * | |
492 | * @param expected_object_size expected size of the object, in bytes | |
493 | * @param expected_write_size expected size of writes to the object, in bytes | |
494 | * @param flags flags () | |
495 | */ | |
496 | void set_alloc_hint(uint64_t expected_object_size, | |
497 | uint64_t expected_write_size); | |
498 | void set_alloc_hint2(uint64_t expected_object_size, | |
499 | uint64_t expected_write_size, | |
500 | uint32_t flags); | |
501 | ||
502 | /** | |
503 | * Pin/unpin an object in cache tier | |
504 | * | |
505 | * @returns 0 on success, negative error code on failure | |
506 | */ | |
507 | void cache_pin(); | |
508 | void cache_unpin(); | |
509 | ||
31f18b77 FG |
510 | /** |
511 | * Extensible tier | |
512 | * | |
513 | * Set redirect target | |
514 | */ | |
515 | void set_redirect(const std::string& tgt_obj, const IoCtx& tgt_ioctx, | |
11fdf7f2 TL |
516 | uint64_t tgt_version, int flag = 0); |
517 | void set_chunk(uint64_t src_offset, uint64_t src_length, const IoCtx& tgt_ioctx, | |
518 | std::string tgt_oid, uint64_t tgt_offset, int flag = 0); | |
519 | void tier_promote(); | |
520 | void unset_manifest(); | |
9f95a23c | 521 | void tier_flush(); |
11fdf7f2 | 522 | |
31f18b77 | 523 | |
7c673cae FG |
524 | friend class IoCtx; |
525 | }; | |
526 | ||
527 | /* | |
528 | * ObjectReadOperation : compound object operation that return value | |
529 | * Batch multiple object operations into a single request, to be applied | |
530 | * atomically. | |
531 | */ | |
532 | class CEPH_RADOS_API ObjectReadOperation : public ObjectOperation | |
533 | { | |
534 | public: | |
535 | ObjectReadOperation() {} | |
536 | ~ObjectReadOperation() override {} | |
537 | ||
9f95a23c TL |
538 | ObjectReadOperation(ObjectReadOperation&&) = default; |
539 | ObjectReadOperation& operator =(ObjectReadOperation&&) = default; | |
540 | ||
7c673cae FG |
541 | void stat(uint64_t *psize, time_t *pmtime, int *prval); |
542 | void stat2(uint64_t *psize, struct timespec *pts, int *prval); | |
543 | void getxattr(const char *name, bufferlist *pbl, int *prval); | |
544 | void getxattrs(std::map<std::string, bufferlist> *pattrs, int *prval); | |
545 | void read(size_t off, uint64_t len, bufferlist *pbl, int *prval); | |
546 | void checksum(rados_checksum_type_t type, const bufferlist &init_value_bl, | |
547 | uint64_t off, size_t len, size_t chunk_size, bufferlist *pbl, | |
548 | int *prval); | |
549 | ||
550 | /** | |
551 | * see aio_sparse_read() | |
552 | */ | |
553 | void sparse_read(uint64_t off, uint64_t len, std::map<uint64_t,uint64_t> *m, | |
554 | bufferlist *data_bl, int *prval); | |
7c673cae FG |
555 | |
556 | /** | |
557 | * omap_get_vals: keys and values from the object omap | |
558 | * | |
559 | * Get up to max_return keys and values beginning after start_after | |
560 | * | |
561 | * @param start_after [in] list no keys smaller than start_after | |
562 | * @param max_return [in] list no more than max_return key/value pairs | |
563 | * @param out_vals [out] place returned values in out_vals on completion | |
564 | * @param prval [out] place error code in prval upon completion | |
565 | */ | |
566 | void omap_get_vals( | |
567 | const std::string &start_after, | |
568 | uint64_t max_return, | |
569 | std::map<std::string, bufferlist> *out_vals, | |
570 | int *prval) __attribute__ ((deprecated)); // use v2 | |
571 | ||
572 | /** | |
573 | * omap_get_vals: keys and values from the object omap | |
574 | * | |
575 | * Get up to max_return keys and values beginning after start_after | |
576 | * | |
577 | * @param start_after [in] list no keys smaller than start_after | |
578 | * @param max_return [in] list no more than max_return key/value pairs | |
579 | * @param out_vals [out] place returned values in out_vals on completion | |
580 | * @param prval [out] place error code in prval upon completion | |
581 | */ | |
582 | void omap_get_vals2( | |
583 | const std::string &start_after, | |
584 | uint64_t max_return, | |
585 | std::map<std::string, bufferlist> *out_vals, | |
586 | bool *pmore, | |
587 | int *prval); | |
588 | ||
589 | /** | |
590 | * omap_get_vals: keys and values from the object omap | |
591 | * | |
592 | * Get up to max_return keys and values beginning after start_after | |
593 | * | |
594 | * @param start_after [in] list keys starting after start_after | |
595 | * @param filter_prefix [in] list only keys beginning with filter_prefix | |
596 | * @param max_return [in] list no more than max_return key/value pairs | |
597 | * @param out_vals [out] place returned values in out_vals on completion | |
598 | * @param prval [out] place error code in prval upon completion | |
599 | */ | |
600 | void omap_get_vals( | |
601 | const std::string &start_after, | |
602 | const std::string &filter_prefix, | |
603 | uint64_t max_return, | |
604 | std::map<std::string, bufferlist> *out_vals, | |
605 | int *prval) __attribute__ ((deprecated)); // use v2 | |
606 | ||
607 | /** | |
608 | * omap_get_vals2: keys and values from the object omap | |
609 | * | |
610 | * Get up to max_return keys and values beginning after start_after | |
611 | * | |
612 | * @param start_after [in] list keys starting after start_after | |
613 | * @param filter_prefix [in] list only keys beginning with filter_prefix | |
614 | * @param max_return [in] list no more than max_return key/value pairs | |
615 | * @param out_vals [out] place returned values in out_vals on completion | |
616 | * @param pmore [out] pointer to bool indicating whether there are more keys | |
617 | * @param prval [out] place error code in prval upon completion | |
618 | */ | |
619 | void omap_get_vals2( | |
620 | const std::string &start_after, | |
621 | const std::string &filter_prefix, | |
622 | uint64_t max_return, | |
623 | std::map<std::string, bufferlist> *out_vals, | |
624 | bool *pmore, | |
625 | int *prval); | |
626 | ||
627 | ||
628 | /** | |
629 | * omap_get_keys: keys from the object omap | |
630 | * | |
631 | * Get up to max_return keys beginning after start_after | |
632 | * | |
633 | * @param start_after [in] list keys starting after start_after | |
634 | * @param max_return [in] list no more than max_return keys | |
635 | * @param out_keys [out] place returned values in out_keys on completion | |
636 | * @param prval [out] place error code in prval upon completion | |
637 | */ | |
638 | void omap_get_keys(const std::string &start_after, | |
639 | uint64_t max_return, | |
640 | std::set<std::string> *out_keys, | |
641 | int *prval) __attribute__ ((deprecated)); // use v2 | |
642 | ||
643 | /** | |
644 | * omap_get_keys2: keys from the object omap | |
645 | * | |
646 | * Get up to max_return keys beginning after start_after | |
647 | * | |
648 | * @param start_after [in] list keys starting after start_after | |
649 | * @param max_return [in] list no more than max_return keys | |
650 | * @param out_keys [out] place returned values in out_keys on completion | |
651 | * @param pmore [out] pointer to bool indicating whether there are more keys | |
652 | * @param prval [out] place error code in prval upon completion | |
653 | */ | |
654 | void omap_get_keys2(const std::string &start_after, | |
655 | uint64_t max_return, | |
656 | std::set<std::string> *out_keys, | |
657 | bool *pmore, | |
658 | int *prval); | |
659 | ||
660 | /** | |
661 | * omap_get_header: get header from object omap | |
662 | * | |
663 | * @param header [out] place header here upon completion | |
664 | * @param prval [out] place error code in prval upon completion | |
665 | */ | |
666 | void omap_get_header(bufferlist *header, int *prval); | |
667 | ||
668 | /** | |
669 | * get key/value pairs for specified keys | |
670 | * | |
671 | * @param keys [in] keys to get | |
672 | * @param map [out] place key/value pairs found here on completion | |
673 | * @param prval [out] place error code in prval upon completion | |
674 | */ | |
675 | void omap_get_vals_by_keys(const std::set<std::string> &keys, | |
676 | std::map<std::string, bufferlist> *map, | |
677 | int *prval); | |
678 | ||
679 | /** | |
680 | * list_watchers: Get list watchers of object | |
681 | * | |
682 | * @param out_watchers [out] place returned values in out_watchers on completion | |
683 | * @param prval [out] place error code in prval upon completion | |
684 | */ | |
685 | void list_watchers(std::list<obj_watch_t> *out_watchers, int *prval); | |
686 | ||
687 | /** | |
688 | * list snapshot clones associated with a logical object | |
689 | * | |
690 | * This will include a record for each version of the object, | |
691 | * include the "HEAD" (which will have a cloneid of SNAP_HEAD). | |
692 | * Each clone includes a vector of snap ids for which it is | |
693 | * defined to exist. | |
694 | * | |
695 | * NOTE: this operation must be submitted from an IoCtx with a | |
696 | * read snapid of SNAP_DIR for reliable results. | |
697 | * | |
698 | * @param out_snaps [out] pointer to resulting snap_set_t | |
699 | * @param prval [out] place error code in prval upon completion | |
700 | */ | |
701 | void list_snaps(snap_set_t *out_snaps, int *prval); | |
702 | ||
703 | /** | |
704 | * query dirty state of an object | |
705 | * | |
706 | * @param isdirty [out] pointer to resulting bool | |
707 | * @param prval [out] place error code in prval upon completion | |
708 | */ | |
709 | void is_dirty(bool *isdirty, int *prval); | |
710 | ||
711 | /** | |
712 | * flush a cache tier object to backing tier; will block racing | |
713 | * updates. | |
714 | * | |
715 | * This should be used in concert with OPERATION_IGNORE_CACHE to avoid | |
716 | * triggering a promotion. | |
717 | */ | |
718 | void cache_flush(); | |
719 | ||
720 | /** | |
721 | * Flush a cache tier object to backing tier; will EAGAIN if we race | |
722 | * with an update. Must be used with the SKIPRWLOCKS flag. | |
723 | * | |
724 | * This should be used in concert with OPERATION_IGNORE_CACHE to avoid | |
725 | * triggering a promotion. | |
726 | */ | |
727 | void cache_try_flush(); | |
728 | ||
729 | /** | |
730 | * evict a clean cache tier object | |
731 | * | |
732 | * This should be used in concert with OPERATION_IGNORE_CACHE to avoid | |
733 | * triggering a promote on the OSD (that is then evicted). | |
734 | */ | |
735 | void cache_evict(); | |
736 | }; | |
737 | ||
738 | /* IoCtx : This is a context in which we can perform I/O. | |
739 | * It includes a Pool, | |
740 | * | |
741 | * Typical use (error checking omitted): | |
742 | * | |
743 | * IoCtx p; | |
744 | * rados.ioctx_create("my_pool", p); | |
745 | * p->stat(&stats); | |
746 | * ... etc ... | |
747 | * | |
748 | * NOTE: be sure to call watch_flush() prior to destroying any IoCtx | |
749 | * that is used for watch events to ensure that racing callbacks | |
750 | * have completed. | |
751 | */ | |
752 | class CEPH_RADOS_API IoCtx | |
753 | { | |
754 | public: | |
755 | IoCtx(); | |
756 | static void from_rados_ioctx_t(rados_ioctx_t p, IoCtx &pool); | |
757 | IoCtx(const IoCtx& rhs); | |
758 | IoCtx& operator=(const IoCtx& rhs); | |
11fdf7f2 TL |
759 | IoCtx(IoCtx&& rhs) noexcept; |
760 | IoCtx& operator=(IoCtx&& rhs) noexcept; | |
7c673cae FG |
761 | |
762 | ~IoCtx(); | |
763 | ||
eafe8130 TL |
764 | bool is_valid() const; |
765 | ||
7c673cae FG |
766 | // Close our pool handle |
767 | void close(); | |
768 | ||
769 | // deep copy | |
770 | void dup(const IoCtx& rhs); | |
771 | ||
772 | // set pool auid | |
11fdf7f2 TL |
773 | int set_auid(uint64_t auid_) |
774 | __attribute__ ((deprecated)); | |
7c673cae FG |
775 | |
776 | // set pool auid | |
11fdf7f2 TL |
777 | int set_auid_async(uint64_t auid_, PoolAsyncCompletion *c) |
778 | __attribute__ ((deprecated)); | |
7c673cae FG |
779 | |
780 | // get pool auid | |
11fdf7f2 TL |
781 | int get_auid(uint64_t *auid_) |
782 | __attribute__ ((deprecated)); | |
7c673cae FG |
783 | |
784 | uint64_t get_instance_id() const; | |
785 | ||
786 | std::string get_pool_name(); | |
787 | ||
788 | bool pool_requires_alignment(); | |
11fdf7f2 | 789 | int pool_requires_alignment2(bool * req); |
7c673cae FG |
790 | uint64_t pool_required_alignment(); |
791 | int pool_required_alignment2(uint64_t * alignment); | |
792 | ||
793 | // create an object | |
794 | int create(const std::string& oid, bool exclusive); | |
795 | int create(const std::string& oid, bool exclusive, | |
796 | const std::string& category); ///< category is unused | |
797 | ||
798 | /** | |
799 | * write bytes to an object at a specified offset | |
800 | * | |
801 | * NOTE: this call steals the contents of @param bl. | |
802 | */ | |
803 | int write(const std::string& oid, bufferlist& bl, size_t len, uint64_t off); | |
804 | /** | |
805 | * append bytes to an object | |
806 | * | |
807 | * NOTE: this call steals the contents of @param bl. | |
808 | */ | |
809 | int append(const std::string& oid, bufferlist& bl, size_t len); | |
810 | /** | |
811 | * replace object contents with provided data | |
812 | * | |
813 | * NOTE: this call steals the contents of @param bl. | |
814 | */ | |
815 | int write_full(const std::string& oid, bufferlist& bl); | |
816 | int writesame(const std::string& oid, bufferlist& bl, | |
817 | size_t write_len, uint64_t off); | |
818 | int read(const std::string& oid, bufferlist& bl, size_t len, uint64_t off); | |
819 | int checksum(const std::string& o, rados_checksum_type_t type, | |
820 | const bufferlist &init_value_bl, size_t len, uint64_t off, | |
821 | size_t chunk_size, bufferlist *pbl); | |
822 | int remove(const std::string& oid); | |
823 | int remove(const std::string& oid, int flags); | |
824 | int trunc(const std::string& oid, uint64_t size); | |
825 | int mapext(const std::string& o, uint64_t off, size_t len, std::map<uint64_t,uint64_t>& m); | |
826 | int cmpext(const std::string& o, uint64_t off, bufferlist& cmp_bl); | |
827 | int sparse_read(const std::string& o, std::map<uint64_t,uint64_t>& m, bufferlist& bl, size_t len, uint64_t off); | |
828 | int getxattr(const std::string& oid, const char *name, bufferlist& bl); | |
829 | int getxattrs(const std::string& oid, std::map<std::string, bufferlist>& attrset); | |
830 | int setxattr(const std::string& oid, const char *name, bufferlist& bl); | |
831 | int rmxattr(const std::string& oid, const char *name); | |
832 | int stat(const std::string& oid, uint64_t *psize, time_t *pmtime); | |
833 | int stat2(const std::string& oid, uint64_t *psize, struct timespec *pts); | |
834 | int exec(const std::string& oid, const char *cls, const char *method, | |
835 | bufferlist& inbl, bufferlist& outbl); | |
836 | /** | |
837 | * modify object tmap based on encoded update sequence | |
838 | * | |
839 | * NOTE: this call steals the contents of @param bl | |
840 | */ | |
841 | int tmap_update(const std::string& oid, bufferlist& cmdbl); | |
7c673cae FG |
842 | |
843 | int omap_get_vals(const std::string& oid, | |
844 | const std::string& start_after, | |
845 | uint64_t max_return, | |
846 | std::map<std::string, bufferlist> *out_vals); | |
847 | int omap_get_vals2(const std::string& oid, | |
848 | const std::string& start_after, | |
849 | uint64_t max_return, | |
850 | std::map<std::string, bufferlist> *out_vals, | |
851 | bool *pmore); | |
852 | int omap_get_vals(const std::string& oid, | |
853 | const std::string& start_after, | |
854 | const std::string& filter_prefix, | |
855 | uint64_t max_return, | |
856 | std::map<std::string, bufferlist> *out_vals); | |
857 | int omap_get_vals2(const std::string& oid, | |
858 | const std::string& start_after, | |
859 | const std::string& filter_prefix, | |
860 | uint64_t max_return, | |
861 | std::map<std::string, bufferlist> *out_vals, | |
862 | bool *pmore); | |
863 | int omap_get_keys(const std::string& oid, | |
864 | const std::string& start_after, | |
865 | uint64_t max_return, | |
866 | std::set<std::string> *out_keys); | |
867 | int omap_get_keys2(const std::string& oid, | |
868 | const std::string& start_after, | |
869 | uint64_t max_return, | |
870 | std::set<std::string> *out_keys, | |
871 | bool *pmore); | |
872 | int omap_get_header(const std::string& oid, | |
873 | bufferlist *bl); | |
874 | int omap_get_vals_by_keys(const std::string& oid, | |
875 | const std::set<std::string>& keys, | |
876 | std::map<std::string, bufferlist> *vals); | |
877 | int omap_set(const std::string& oid, | |
878 | const std::map<std::string, bufferlist>& map); | |
879 | int omap_set_header(const std::string& oid, | |
880 | const bufferlist& bl); | |
881 | int omap_clear(const std::string& oid); | |
882 | int omap_rm_keys(const std::string& oid, | |
883 | const std::set<std::string>& keys); | |
884 | ||
885 | void snap_set_read(snap_t seq); | |
886 | int selfmanaged_snap_set_write_ctx(snap_t seq, std::vector<snap_t>& snaps); | |
887 | ||
888 | // Create a snapshot with a given name | |
889 | int snap_create(const char *snapname); | |
890 | ||
891 | // Look up a snapshot by name. | |
892 | // Returns 0 on success; error code otherwise | |
893 | int snap_lookup(const char *snapname, snap_t *snap); | |
894 | ||
895 | // Gets a timestamp for a snap | |
896 | int snap_get_stamp(snap_t snapid, time_t *t); | |
897 | ||
898 | // Gets the name of a snap | |
899 | int snap_get_name(snap_t snapid, std::string *s); | |
900 | ||
901 | // Remove a snapshot from this pool | |
902 | int snap_remove(const char *snapname); | |
903 | ||
904 | int snap_list(std::vector<snap_t> *snaps); | |
905 | ||
906 | int snap_rollback(const std::string& oid, const char *snapname); | |
907 | ||
908 | // Deprecated name kept for backward compatibility - same as snap_rollback() | |
909 | int rollback(const std::string& oid, const char *snapname) | |
910 | __attribute__ ((deprecated)); | |
911 | ||
912 | int selfmanaged_snap_create(uint64_t *snapid); | |
913 | void aio_selfmanaged_snap_create(uint64_t *snapid, AioCompletion *c); | |
914 | ||
915 | int selfmanaged_snap_remove(uint64_t snapid); | |
916 | void aio_selfmanaged_snap_remove(uint64_t snapid, AioCompletion *c); | |
917 | ||
918 | int selfmanaged_snap_rollback(const std::string& oid, uint64_t snapid); | |
919 | ||
920 | // Advisory locking on rados objects. | |
921 | int lock_exclusive(const std::string &oid, const std::string &name, | |
922 | const std::string &cookie, | |
923 | const std::string &description, | |
924 | struct timeval * duration, uint8_t flags); | |
925 | ||
926 | int lock_shared(const std::string &oid, const std::string &name, | |
927 | const std::string &cookie, const std::string &tag, | |
928 | const std::string &description, | |
929 | struct timeval * duration, uint8_t flags); | |
930 | ||
931 | int unlock(const std::string &oid, const std::string &name, | |
932 | const std::string &cookie); | |
933 | ||
934 | int break_lock(const std::string &oid, const std::string &name, | |
935 | const std::string &client, const std::string &cookie); | |
936 | ||
937 | int list_lockers(const std::string &oid, const std::string &name, | |
938 | int *exclusive, | |
939 | std::string *tag, | |
940 | std::list<librados::locker_t> *lockers); | |
941 | ||
942 | ||
f64942e4 | 943 | /// Start enumerating objects for a pool. Errors are thrown as exceptions. |
11fdf7f2 | 944 | NObjectIterator nobjects_begin(const bufferlist &filter=bufferlist()); |
f64942e4 AA |
945 | /// Start enumerating objects for a pool starting from a hash position. |
946 | /// Errors are thrown as exceptions. | |
7c673cae | 947 | NObjectIterator nobjects_begin(uint32_t start_hash_position, |
11fdf7f2 | 948 | const bufferlist &filter=bufferlist()); |
f64942e4 AA |
949 | /// Start enumerating objects for a pool starting from cursor. Errors are |
950 | /// thrown as exceptions. | |
7c673cae | 951 | NObjectIterator nobjects_begin(const librados::ObjectCursor& cursor, |
11fdf7f2 | 952 | const bufferlist &filter=bufferlist()); |
7c673cae FG |
953 | /// Iterator indicating the end of a pool |
954 | const NObjectIterator& nobjects_end() const; | |
955 | ||
956 | /// Get cursor for pool beginning | |
957 | ObjectCursor object_list_begin(); | |
958 | ||
959 | /// Get cursor for pool end | |
960 | ObjectCursor object_list_end(); | |
961 | ||
962 | /// Check whether a cursor is at the end of a pool | |
963 | bool object_list_is_end(const ObjectCursor &oc); | |
964 | ||
965 | /// List some objects between two cursors | |
966 | int object_list(const ObjectCursor &start, const ObjectCursor &finish, | |
967 | const size_t result_count, | |
968 | const bufferlist &filter, | |
969 | std::vector<ObjectItem> *result, | |
970 | ObjectCursor *next); | |
971 | ||
972 | /// Generate cursors that include the N out of Mth slice of the pool | |
973 | void object_list_slice( | |
974 | const ObjectCursor start, | |
975 | const ObjectCursor finish, | |
976 | const size_t n, | |
977 | const size_t m, | |
978 | ObjectCursor *split_start, | |
979 | ObjectCursor *split_finish); | |
980 | ||
981 | /** | |
982 | * List available hit set objects | |
983 | * | |
984 | * @param uint32_t [in] hash position to query | |
985 | * @param c [in] completion | |
986 | * @param pls [out] list of available intervals | |
987 | */ | |
988 | int hit_set_list(uint32_t hash, AioCompletion *c, | |
989 | std::list< std::pair<time_t, time_t> > *pls); | |
990 | ||
991 | /** | |
992 | * Retrieve hit set for a given hash, and time | |
993 | * | |
994 | * @param hash [in] hash position | |
995 | * @param c [in] completion | |
996 | * @param stamp [in] time interval that falls within the hit set's interval | |
997 | * @param pbl [out] buffer to store the result in | |
998 | */ | |
999 | int hit_set_get(uint32_t hash, AioCompletion *c, time_t stamp, | |
1000 | bufferlist *pbl); | |
1001 | ||
1002 | uint64_t get_last_version(); | |
1003 | ||
1004 | int aio_read(const std::string& oid, AioCompletion *c, | |
1005 | bufferlist *pbl, size_t len, uint64_t off); | |
1006 | /** | |
1007 | * Asynchronously read from an object at a particular snapshot | |
1008 | * | |
1009 | * This is the same as normal aio_read, except that it chooses | |
1010 | * the snapshot to read from from its arguments instead of the | |
1011 | * internal IoCtx state. | |
1012 | * | |
1013 | * The return value of the completion will be number of bytes read on | |
1014 | * success, negative error code on failure. | |
1015 | * | |
1016 | * @param oid the name of the object to read from | |
1017 | * @param c what to do when the read is complete | |
1018 | * @param pbl where to store the results | |
1019 | * @param len the number of bytes to read | |
1020 | * @param off the offset to start reading from in the object | |
1021 | * @param snapid the id of the snapshot to read from | |
1022 | * @returns 0 on success, negative error code on failure | |
1023 | */ | |
1024 | int aio_read(const std::string& oid, AioCompletion *c, | |
1025 | bufferlist *pbl, size_t len, uint64_t off, uint64_t snapid); | |
1026 | int aio_sparse_read(const std::string& oid, AioCompletion *c, | |
1027 | std::map<uint64_t,uint64_t> *m, bufferlist *data_bl, | |
1028 | size_t len, uint64_t off); | |
1029 | /** | |
1030 | * Asynchronously read existing extents from an object at a | |
1031 | * particular snapshot | |
1032 | * | |
1033 | * This is the same as normal aio_sparse_read, except that it chooses | |
1034 | * the snapshot to read from from its arguments instead of the | |
1035 | * internal IoCtx state. | |
1036 | * | |
1037 | * m will be filled in with a map of extents in the object, | |
1038 | * mapping offsets to lengths (in bytes) within the range | |
1039 | * requested. The data for all of the extents are stored | |
1040 | * back-to-back in offset order in data_bl. | |
1041 | * | |
1042 | * @param oid the name of the object to read from | |
1043 | * @param c what to do when the read is complete | |
1044 | * @param m where to store the map of extents | |
1045 | * @param data_bl where to store the data | |
1046 | * @param len the number of bytes to read | |
1047 | * @param off the offset to start reading from in the object | |
1048 | * @param snapid the id of the snapshot to read from | |
1049 | * @returns 0 on success, negative error code on failure | |
1050 | */ | |
1051 | int aio_sparse_read(const std::string& oid, AioCompletion *c, | |
1052 | std::map<uint64_t,uint64_t> *m, bufferlist *data_bl, | |
1053 | size_t len, uint64_t off, uint64_t snapid); | |
1054 | /** | |
1055 | * Asynchronously compare an on-disk object range with a buffer | |
1056 | * | |
1057 | * @param oid the name of the object to read from | |
1058 | * @param c what to do when the read is complete | |
1059 | * @param off object byte offset at which to start the comparison | |
1060 | * @param cmp_bl buffer containing bytes to be compared with object contents | |
1061 | * @returns 0 on success, negative error code on failure, | |
1062 | * (-MAX_ERRNO - mismatch_off) on mismatch | |
1063 | */ | |
1064 | int aio_cmpext(const std::string& oid, | |
1065 | librados::AioCompletion *c, | |
1066 | uint64_t off, | |
1067 | bufferlist& cmp_bl); | |
1068 | int aio_write(const std::string& oid, AioCompletion *c, const bufferlist& bl, | |
1069 | size_t len, uint64_t off); | |
1070 | int aio_append(const std::string& oid, AioCompletion *c, const bufferlist& bl, | |
1071 | size_t len); | |
1072 | int aio_write_full(const std::string& oid, AioCompletion *c, const bufferlist& bl); | |
1073 | int aio_writesame(const std::string& oid, AioCompletion *c, const bufferlist& bl, | |
1074 | size_t write_len, uint64_t off); | |
1075 | ||
1076 | /** | |
11fdf7f2 | 1077 | * Asynchronously remove an object |
7c673cae FG |
1078 | * |
1079 | * Queues the remove and returns. | |
1080 | * | |
1081 | * The return value of the completion will be 0 on success, negative | |
1082 | * error code on failure. | |
1083 | * | |
1084 | * @param oid the name of the object | |
1085 | * @param c what to do when the remove is safe and complete | |
1086 | * @returns 0 on success, -EROFS if the io context specifies a snap_seq | |
1087 | * other than SNAP_HEAD | |
1088 | */ | |
1089 | int aio_remove(const std::string& oid, AioCompletion *c); | |
1090 | int aio_remove(const std::string& oid, AioCompletion *c, int flags); | |
1091 | ||
1092 | /** | |
1093 | * Wait for all currently pending aio writes to be safe. | |
1094 | * | |
1095 | * @returns 0 on success, negative error code on failure | |
1096 | */ | |
1097 | int aio_flush(); | |
1098 | ||
1099 | /** | |
1100 | * Schedule a callback for when all currently pending | |
1101 | * aio writes are safe. This is a non-blocking version of | |
1102 | * aio_flush(). | |
1103 | * | |
1104 | * @param c what to do when the writes are safe | |
1105 | * @returns 0 on success, negative error code on failure | |
1106 | */ | |
1107 | int aio_flush_async(AioCompletion *c); | |
1108 | int aio_getxattr(const std::string& oid, AioCompletion *c, const char *name, bufferlist& bl); | |
1109 | int aio_getxattrs(const std::string& oid, AioCompletion *c, std::map<std::string, bufferlist>& attrset); | |
1110 | int aio_setxattr(const std::string& oid, AioCompletion *c, const char *name, bufferlist& bl); | |
1111 | int aio_rmxattr(const std::string& oid, AioCompletion *c, const char *name); | |
1112 | int aio_stat(const std::string& oid, AioCompletion *c, uint64_t *psize, time_t *pmtime); | |
1113 | int aio_stat2(const std::string& oid, AioCompletion *c, uint64_t *psize, struct timespec *pts); | |
1114 | ||
1115 | /** | |
1116 | * Cancel aio operation | |
1117 | * | |
1118 | * @param c completion handle | |
1119 | * @returns 0 on success, negative error code on failure | |
1120 | */ | |
1121 | int aio_cancel(AioCompletion *c); | |
1122 | ||
1123 | int aio_exec(const std::string& oid, AioCompletion *c, const char *cls, const char *method, | |
1124 | bufferlist& inbl, bufferlist *outbl); | |
1125 | ||
1126 | /* | |
1127 | * asynchronous version of unlock | |
1128 | */ | |
1129 | int aio_unlock(const std::string &oid, const std::string &name, | |
1130 | const std::string &cookie, AioCompletion *c); | |
1131 | ||
1132 | // compound object operations | |
1133 | int operate(const std::string& oid, ObjectWriteOperation *op); | |
9f95a23c | 1134 | int operate(const std::string& oid, ObjectWriteOperation *op, int flags); |
7c673cae | 1135 | int operate(const std::string& oid, ObjectReadOperation *op, bufferlist *pbl); |
9f95a23c | 1136 | int operate(const std::string& oid, ObjectReadOperation *op, bufferlist *pbl, int flags); |
7c673cae FG |
1137 | int aio_operate(const std::string& oid, AioCompletion *c, ObjectWriteOperation *op); |
1138 | int aio_operate(const std::string& oid, AioCompletion *c, ObjectWriteOperation *op, int flags); | |
1139 | /** | |
1140 | * Schedule an async write operation with explicit snapshot parameters | |
1141 | * | |
1142 | * This is the same as the first aio_operate(), except that it | |
1143 | * gets the snapshot context from its arguments instead of the | |
1144 | * IoCtx internal state. | |
1145 | * | |
1146 | * @param oid the object to operate on | |
1147 | * @param c what to do when the operation is complete and safe | |
1148 | * @param op which operations to perform | |
1149 | * @param seq latest selfmanaged snapshot sequence number for this object | |
1150 | * @param snaps currently existing selfmanaged snapshot ids for this object | |
1151 | * @returns 0 on success, negative error code on failure | |
1152 | */ | |
1153 | int aio_operate(const std::string& oid, AioCompletion *c, | |
1154 | ObjectWriteOperation *op, snap_t seq, | |
1155 | std::vector<snap_t>& snaps); | |
1156 | int aio_operate(const std::string& oid, AioCompletion *c, | |
1157 | ObjectWriteOperation *op, snap_t seq, | |
1158 | std::vector<snap_t>& snaps, | |
1159 | const blkin_trace_info *trace_info); | |
11fdf7f2 TL |
1160 | int aio_operate(const std::string& oid, AioCompletion *c, |
1161 | ObjectWriteOperation *op, snap_t seq, | |
1162 | std::vector<snap_t>& snaps, int flags, | |
1163 | const blkin_trace_info *trace_info); | |
7c673cae FG |
1164 | int aio_operate(const std::string& oid, AioCompletion *c, |
1165 | ObjectReadOperation *op, bufferlist *pbl); | |
1166 | ||
1167 | int aio_operate(const std::string& oid, AioCompletion *c, | |
1168 | ObjectReadOperation *op, snap_t snapid, int flags, | |
1169 | bufferlist *pbl) | |
1170 | __attribute__ ((deprecated)); | |
1171 | ||
1172 | int aio_operate(const std::string& oid, AioCompletion *c, | |
1173 | ObjectReadOperation *op, int flags, | |
1174 | bufferlist *pbl); | |
1175 | int aio_operate(const std::string& oid, AioCompletion *c, | |
1176 | ObjectReadOperation *op, int flags, | |
1177 | bufferlist *pbl, const blkin_trace_info *trace_info); | |
1178 | ||
1179 | // watch/notify | |
1180 | int watch2(const std::string& o, uint64_t *handle, | |
1181 | librados::WatchCtx2 *ctx); | |
1182 | int watch3(const std::string& o, uint64_t *handle, | |
1183 | librados::WatchCtx2 *ctx, uint32_t timeout); | |
1184 | int aio_watch(const std::string& o, AioCompletion *c, uint64_t *handle, | |
1185 | librados::WatchCtx2 *ctx); | |
1186 | int aio_watch2(const std::string& o, AioCompletion *c, uint64_t *handle, | |
1187 | librados::WatchCtx2 *ctx, uint32_t timeout); | |
1188 | int unwatch2(uint64_t handle); | |
1189 | int aio_unwatch(uint64_t handle, AioCompletion *c); | |
1190 | /** | |
11fdf7f2 | 1191 | * Send a notify event to watchers |
7c673cae FG |
1192 | * |
1193 | * Upon completion the pbl bufferlist reply payload will be | |
1194 | * encoded like so: | |
1195 | * | |
1196 | * le32 num_acks | |
1197 | * { | |
1198 | * le64 gid global id for the client (for client.1234 that's 1234) | |
1199 | * le64 cookie cookie for the client | |
1200 | * le32 buflen length of reply message buffer | |
1201 | * u8 * buflen payload | |
1202 | * } * num_acks | |
1203 | * le32 num_timeouts | |
1204 | * { | |
1205 | * le64 gid global id for the client | |
1206 | * le64 cookie cookie for the client | |
1207 | * } * num_timeouts | |
1208 | * | |
1209 | * | |
1210 | */ | |
1211 | int notify2(const std::string& o, ///< object | |
1212 | bufferlist& bl, ///< optional broadcast payload | |
1213 | uint64_t timeout_ms, ///< timeout (in ms) | |
1214 | bufferlist *pbl); ///< reply buffer | |
1215 | int aio_notify(const std::string& o, ///< object | |
1216 | AioCompletion *c, ///< completion when notify completes | |
1217 | bufferlist& bl, ///< optional broadcast payload | |
1218 | uint64_t timeout_ms, ///< timeout (in ms) | |
1219 | bufferlist *pbl); ///< reply buffer | |
1220 | ||
1221 | int list_watchers(const std::string& o, std::list<obj_watch_t> *out_watchers); | |
1222 | int list_snaps(const std::string& o, snap_set_t *out_snaps); | |
1223 | void set_notify_timeout(uint32_t timeout); | |
1224 | ||
1225 | /// acknowledge a notify we received. | |
1226 | void notify_ack(const std::string& o, ///< watched object | |
1227 | uint64_t notify_id, ///< notify id | |
1228 | uint64_t cookie, ///< our watch handle | |
1229 | bufferlist& bl); ///< optional reply payload | |
1230 | ||
1231 | /*** | |
1232 | * check on watch validity | |
1233 | * | |
1234 | * Check if a watch is valid. If so, return the number of | |
1235 | * milliseconds since we last confirmed its liveness. If there is | |
1236 | * a known error, return it. | |
1237 | * | |
1238 | * If there is an error, the watch is no longer valid, and should | |
11fdf7f2 TL |
1239 | * be destroyed with unwatch(). The user is still interested in |
1240 | * the object, a new watch should be created with watch(). | |
7c673cae FG |
1241 | * |
1242 | * @param cookie watch handle | |
1243 | * @returns ms since last confirmed valid, or error | |
1244 | */ | |
1245 | int watch_check(uint64_t cookie); | |
1246 | ||
1247 | // old, deprecated versions | |
1248 | int watch(const std::string& o, uint64_t ver, uint64_t *cookie, | |
1249 | librados::WatchCtx *ctx) __attribute__ ((deprecated)); | |
1250 | int notify(const std::string& o, uint64_t ver, bufferlist& bl) | |
1251 | __attribute__ ((deprecated)); | |
1252 | int unwatch(const std::string& o, uint64_t cookie) | |
1253 | __attribute__ ((deprecated)); | |
1254 | ||
1255 | /** | |
1256 | * Set allocation hint for an object | |
1257 | * | |
1258 | * This is an advisory operation, it will always succeed (as if it | |
1259 | * was submitted with a OP_FAILOK flag set) and is not guaranteed | |
1260 | * to do anything on the backend. | |
1261 | * | |
1262 | * @param o the name of the object | |
1263 | * @param expected_object_size expected size of the object, in bytes | |
1264 | * @param expected_write_size expected size of writes to the object, in bytes | |
1265 | * @returns 0 on success, negative error code on failure | |
1266 | */ | |
1267 | int set_alloc_hint(const std::string& o, | |
1268 | uint64_t expected_object_size, | |
1269 | uint64_t expected_write_size); | |
1270 | int set_alloc_hint2(const std::string& o, | |
1271 | uint64_t expected_object_size, | |
1272 | uint64_t expected_write_size, | |
1273 | uint32_t flags); | |
1274 | ||
1275 | // assert version for next sync operations | |
1276 | void set_assert_version(uint64_t ver); | |
1277 | ||
1278 | /** | |
1279 | * Pin/unpin an object in cache tier | |
1280 | * | |
1281 | * @param o the name of the object | |
1282 | * @returns 0 on success, negative error code on failure | |
1283 | */ | |
1284 | int cache_pin(const std::string& o); | |
1285 | int cache_unpin(const std::string& o); | |
1286 | ||
1287 | std::string get_pool_name() const; | |
1288 | ||
1289 | void locator_set_key(const std::string& key); | |
1290 | void set_namespace(const std::string& nspace); | |
11fdf7f2 | 1291 | std::string get_namespace() const; |
7c673cae FG |
1292 | |
1293 | int64_t get_id(); | |
1294 | ||
1295 | // deprecated versions | |
1296 | uint32_t get_object_hash_position(const std::string& oid) | |
1297 | __attribute__ ((deprecated)); | |
1298 | uint32_t get_object_pg_hash_position(const std::string& oid) | |
1299 | __attribute__ ((deprecated)); | |
1300 | ||
1301 | int get_object_hash_position2(const std::string& oid, uint32_t *hash_position); | |
1302 | int get_object_pg_hash_position2(const std::string& oid, uint32_t *pg_hash_position); | |
1303 | ||
1304 | config_t cct(); | |
1305 | ||
9f95a23c TL |
1306 | void set_osdmap_full_try() |
1307 | __attribute__ ((deprecated)); | |
1308 | void unset_osdmap_full_try() | |
1309 | __attribute__ ((deprecated)); | |
1310 | ||
1311 | void set_pool_full_try(); | |
1312 | void unset_pool_full_try(); | |
7c673cae | 1313 | |
c07f9fc5 FG |
1314 | int application_enable(const std::string& app_name, bool force); |
1315 | int application_enable_async(const std::string& app_name, | |
1316 | bool force, PoolAsyncCompletion *c); | |
1317 | int application_list(std::set<std::string> *app_names); | |
1318 | int application_metadata_get(const std::string& app_name, | |
1319 | const std::string &key, | |
1320 | std::string *value); | |
1321 | int application_metadata_set(const std::string& app_name, | |
1322 | const std::string &key, | |
1323 | const std::string& value); | |
1324 | int application_metadata_remove(const std::string& app_name, | |
1325 | const std::string &key); | |
1326 | int application_metadata_list(const std::string& app_name, | |
1327 | std::map<std::string, std::string> *values); | |
1328 | ||
7c673cae FG |
1329 | private: |
1330 | /* You can only get IoCtx instances from Rados */ | |
1331 | IoCtx(IoCtxImpl *io_ctx_impl_); | |
1332 | ||
1333 | friend class Rados; // Only Rados can use our private constructor to create IoCtxes. | |
1334 | friend class libradosstriper::RadosStriper; // Striper needs to see our IoCtxImpl | |
1335 | friend class ObjectWriteOperation; // copy_from needs to see our IoCtxImpl | |
1336 | ||
1337 | IoCtxImpl *io_ctx_impl; | |
1338 | }; | |
1339 | ||
7c673cae FG |
1340 | struct CEPH_RADOS_API PlacementGroup { |
1341 | PlacementGroup(); | |
1342 | PlacementGroup(const PlacementGroup&); | |
1343 | ~PlacementGroup(); | |
1344 | bool parse(const char*); | |
1345 | std::unique_ptr<PlacementGroupImpl> impl; | |
1346 | }; | |
1347 | ||
1348 | CEPH_RADOS_API std::ostream& operator<<(std::ostream&, const PlacementGroup&); | |
1349 | ||
1350 | class CEPH_RADOS_API Rados | |
1351 | { | |
1352 | public: | |
1353 | static void version(int *major, int *minor, int *extra); | |
1354 | ||
1355 | Rados(); | |
1356 | explicit Rados(IoCtx& ioctx); | |
1357 | ~Rados(); | |
eafe8130 | 1358 | static void from_rados_t(rados_t cluster, Rados &rados); |
7c673cae FG |
1359 | |
1360 | int init(const char * const id); | |
1361 | int init2(const char * const name, const char * const clustername, | |
1362 | uint64_t flags); | |
1363 | int init_with_context(config_t cct_); | |
1364 | config_t cct(); | |
1365 | int connect(); | |
1366 | void shutdown(); | |
1367 | int watch_flush(); | |
1368 | int aio_watch_flush(AioCompletion*); | |
1369 | int conf_read_file(const char * const path) const; | |
1370 | int conf_parse_argv(int argc, const char ** argv) const; | |
1371 | int conf_parse_argv_remainder(int argc, const char ** argv, | |
1372 | const char ** remargv) const; | |
1373 | int conf_parse_env(const char *env) const; | |
1374 | int conf_set(const char *option, const char *value); | |
1375 | int conf_get(const char *option, std::string &val); | |
1376 | ||
224ce89b WB |
1377 | int service_daemon_register( |
1378 | const std::string& service, ///< service name (e.g., 'rgw') | |
1379 | const std::string& name, ///< daemon name (e.g., 'gwfoo') | |
1380 | const std::map<std::string,std::string>& metadata); ///< static metadata about daemon | |
1381 | int service_daemon_update_status( | |
11fdf7f2 | 1382 | std::map<std::string,std::string>&& status); |
224ce89b | 1383 | |
7c673cae | 1384 | int pool_create(const char *name); |
11fdf7f2 TL |
1385 | int pool_create(const char *name, uint64_t auid) |
1386 | __attribute__ ((deprecated)); | |
1387 | int pool_create(const char *name, uint64_t auid, uint8_t crush_rule) | |
1388 | __attribute__ ((deprecated)); | |
1389 | int pool_create_with_rule(const char *name, uint8_t crush_rule); | |
7c673cae | 1390 | int pool_create_async(const char *name, PoolAsyncCompletion *c); |
11fdf7f2 TL |
1391 | int pool_create_async(const char *name, uint64_t auid, PoolAsyncCompletion *c) |
1392 | __attribute__ ((deprecated)); | |
1393 | int pool_create_async(const char *name, uint64_t auid, uint8_t crush_rule, PoolAsyncCompletion *c) | |
1394 | __attribute__ ((deprecated)); | |
1395 | int pool_create_with_rule_async(const char *name, uint8_t crush_rule, PoolAsyncCompletion *c); | |
7c673cae FG |
1396 | int pool_get_base_tier(int64_t pool, int64_t* base_tier); |
1397 | int pool_delete(const char *name); | |
1398 | int pool_delete_async(const char *name, PoolAsyncCompletion *c); | |
1399 | int64_t pool_lookup(const char *name); | |
1400 | int pool_reverse_lookup(int64_t id, std::string *name); | |
1401 | ||
1402 | uint64_t get_instance_id(); | |
1403 | ||
11fdf7f2 TL |
1404 | int get_min_compatible_osd(int8_t* require_osd_release); |
1405 | int get_min_compatible_client(int8_t* min_compat_client, | |
1406 | int8_t* require_min_compat_client); | |
1407 | ||
7c673cae FG |
1408 | int mon_command(std::string cmd, const bufferlist& inbl, |
1409 | bufferlist *outbl, std::string *outs); | |
1410 | int mgr_command(std::string cmd, const bufferlist& inbl, | |
1411 | bufferlist *outbl, std::string *outs); | |
1412 | int osd_command(int osdid, std::string cmd, const bufferlist& inbl, | |
1413 | bufferlist *outbl, std::string *outs); | |
1414 | int pg_command(const char *pgstr, std::string cmd, const bufferlist& inbl, | |
1415 | bufferlist *outbl, std::string *outs); | |
1416 | ||
1417 | int ioctx_create(const char *name, IoCtx &pioctx); | |
1418 | int ioctx_create2(int64_t pool_id, IoCtx &pioctx); | |
1419 | ||
1420 | // Features useful for test cases | |
1421 | void test_blacklist_self(bool set); | |
1422 | ||
1423 | /* pool info */ | |
1424 | int pool_list(std::list<std::string>& v); | |
1425 | int pool_list2(std::list<std::pair<int64_t, std::string> >& v); | |
1426 | int get_pool_stats(std::list<std::string>& v, | |
1427 | stats_map& result); | |
1428 | /// deprecated; use simpler form. categories no longer supported. | |
1429 | int get_pool_stats(std::list<std::string>& v, | |
1430 | std::map<std::string, stats_map>& stats); | |
1431 | /// deprecated; categories no longer supported | |
1432 | int get_pool_stats(std::list<std::string>& v, | |
1433 | std::string& category, | |
1434 | std::map<std::string, stats_map>& stats); | |
1435 | /// check if pool has selfmanaged snaps | |
1436 | bool get_pool_is_selfmanaged_snaps_mode(const std::string& poolname); | |
1437 | ||
1438 | int cluster_stat(cluster_stat_t& result); | |
1439 | int cluster_fsid(std::string *fsid); | |
1440 | ||
1441 | /** | |
1442 | * List inconsistent placement groups in the given pool | |
1443 | * | |
1444 | * @param pool_id the pool id | |
1445 | * @param pgs [out] the inconsistent PGs | |
1446 | */ | |
1447 | int get_inconsistent_pgs(int64_t pool_id, | |
1448 | std::vector<PlacementGroup>* pgs); | |
1449 | /** | |
1450 | * List the inconsistent objects found in a given PG by last scrub | |
1451 | * | |
1452 | * @param pg the placement group returned by @c pg_list() | |
1453 | * @param start_after the first returned @c objects | |
1454 | * @param max_return the max number of the returned @c objects | |
1455 | * @param c what to do when the operation is complete and safe | |
1456 | * @param objects [out] the objects where inconsistencies are found | |
1457 | * @param interval [in,out] an epoch indicating current interval | |
1458 | * @returns if a non-zero @c interval is specified, will return -EAGAIN i | |
1459 | * the current interval begin epoch is different. | |
1460 | */ | |
1461 | int get_inconsistent_objects(const PlacementGroup& pg, | |
1462 | const object_id_t &start_after, | |
1463 | unsigned max_return, | |
1464 | AioCompletion *c, | |
1465 | std::vector<inconsistent_obj_t>* objects, | |
1466 | uint32_t* interval); | |
1467 | /** | |
1468 | * List the inconsistent snapsets found in a given PG by last scrub | |
1469 | * | |
1470 | * @param pg the placement group returned by @c pg_list() | |
1471 | * @param start_after the first returned @c objects | |
1472 | * @param max_return the max number of the returned @c objects | |
1473 | * @param c what to do when the operation is complete and safe | |
1474 | * @param snapsets [out] the objects where inconsistencies are found | |
1475 | * @param interval [in,out] an epoch indicating current interval | |
1476 | * @returns if a non-zero @c interval is specified, will return -EAGAIN i | |
1477 | * the current interval begin epoch is different. | |
1478 | */ | |
1479 | int get_inconsistent_snapsets(const PlacementGroup& pg, | |
1480 | const object_id_t &start_after, | |
1481 | unsigned max_return, | |
1482 | AioCompletion *c, | |
1483 | std::vector<inconsistent_snapset_t>* snapset, | |
1484 | uint32_t* interval); | |
1485 | ||
1486 | /// get/wait for the most recent osdmap | |
1487 | int wait_for_latest_osdmap(); | |
1488 | ||
1489 | int blacklist_add(const std::string& client_address, | |
1490 | uint32_t expire_seconds); | |
1491 | ||
1492 | /* | |
1493 | * pool aio | |
1494 | * | |
1495 | * It is up to the caller to release the completion handler, even if the pool_create_async() | |
1496 | * and/or pool_delete_async() fails and does not send the async request | |
1497 | */ | |
1498 | static PoolAsyncCompletion *pool_async_create_completion(); | |
1499 | ||
1500 | // -- aio -- | |
1501 | static AioCompletion *aio_create_completion(); | |
1502 | static AioCompletion *aio_create_completion(void *cb_arg, callback_t cb_complete, | |
9f95a23c TL |
1503 | callback_t cb_safe) |
1504 | __attribute__ ((deprecated)); | |
1505 | static AioCompletion *aio_create_completion(void *cb_arg, callback_t cb_complete); | |
7c673cae FG |
1506 | |
1507 | friend std::ostream& operator<<(std::ostream &oss, const Rados& r); | |
1508 | private: | |
1509 | // We don't allow assignment or copying | |
1510 | Rados(const Rados& rhs); | |
1511 | const Rados& operator=(const Rados& rhs); | |
1512 | RadosClient *client; | |
1513 | }; | |
11fdf7f2 TL |
1514 | |
1515 | } // namespace v14_2_0 | |
1516 | } // namespace librados | |
7c673cae FG |
1517 | |
1518 | #endif | |
1519 |