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