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