Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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     OPERATION_IGNORE_REDIRECT    = LIBRADOS_OPERATION_IGNORE_REDIRECT,
271   };
272
273   /*
274    * Alloc hint flags for the alloc_hint operation.
275    */
276   enum AllocHintFlags {
277     ALLOC_HINT_FLAG_SEQUENTIAL_WRITE = 1,
278     ALLOC_HINT_FLAG_RANDOM_WRITE = 2,
279     ALLOC_HINT_FLAG_SEQUENTIAL_READ = 4,
280     ALLOC_HINT_FLAG_RANDOM_READ = 8,
281     ALLOC_HINT_FLAG_APPEND_ONLY = 16,
282     ALLOC_HINT_FLAG_IMMUTABLE = 32,
283     ALLOC_HINT_FLAG_SHORTLIVED = 64,
284     ALLOC_HINT_FLAG_LONGLIVED = 128,
285     ALLOC_HINT_FLAG_COMPRESSIBLE = 256,
286     ALLOC_HINT_FLAG_INCOMPRESSIBLE = 512,
287   };
288
289   /*
290    * ObjectOperation : compound object operation
291    * Batch multiple object operations into a single request, to be applied
292    * atomically.
293    */
294   class CEPH_RADOS_API ObjectOperation
295   {
296   public:
297     ObjectOperation();
298     virtual ~ObjectOperation();
299
300     size_t size();
301     void set_op_flags(ObjectOperationFlags flags) __attribute__((deprecated));
302     //flag mean ObjectOperationFlags
303     void set_op_flags2(int flags);
304
305     void cmpext(uint64_t off, bufferlist& cmp_bl, int *prval);
306     void cmpxattr(const char *name, uint8_t op, const bufferlist& val);
307     void cmpxattr(const char *name, uint8_t op, uint64_t v);
308     void exec(const char *cls, const char *method, bufferlist& inbl);
309     void exec(const char *cls, const char *method, bufferlist& inbl, bufferlist *obl, int *prval);
310     void exec(const char *cls, const char *method, bufferlist& inbl, ObjectOperationCompletion *completion);
311     /**
312      * Guard operation with a check that object version == ver
313      *
314      * @param ver [in] version to check
315      */
316     void assert_version(uint64_t ver);
317
318     /**
319      * Guard operatation with a check that the object already exists
320      */
321     void assert_exists();
322
323     /**
324      * get key/value pairs for specified keys
325      *
326      * @param assertions [in] comparison assertions
327      * @param prval [out] place error code in prval upon completion
328      *
329      * assertions has the form of mappings from keys to (comparison rval, assertion)
330      * The assertion field may be CEPH_OSD_CMPXATTR_OP_[GT|LT|EQ].
331      *
332      * That is, to assert that the value at key 'foo' is greater than 'bar':
333      *
334      * ObjectReadOperation op;
335      * int r;
336      * map<string, pair<bufferlist, int> > assertions;
337      * bufferlist bar(string('bar'));
338      * assertions['foo'] = make_pair(bar, CEPH_OSD_CMP_XATTR_OP_GT);
339      * op.omap_cmp(assertions, &r);
340      */
341     void omap_cmp(
342       const std::map<std::string, std::pair<bufferlist, int> > &assertions,
343       int *prval);
344
345   protected:
346     ObjectOperationImpl *impl;
347     ObjectOperation(const ObjectOperation& rhs);
348     ObjectOperation& operator=(const ObjectOperation& rhs);
349     friend class IoCtx;
350     friend class Rados;
351   };
352
353   /*
354    * ObjectWriteOperation : compound object write operation
355    * Batch multiple object operations into a single request, to be applied
356    * atomically.
357    */
358   class CEPH_RADOS_API ObjectWriteOperation : public ObjectOperation
359   {
360   protected:
361     time_t *unused;
362   public:
363     ObjectWriteOperation() : unused(NULL) {}
364     ~ObjectWriteOperation() override {}
365
366     void mtime(time_t *pt);
367     void mtime2(struct timespec *pts);
368
369     void create(bool exclusive);
370     void create(bool exclusive,
371                 const std::string& category); ///< NOTE: category is unused
372
373     void write(uint64_t off, const bufferlist& bl);
374     void write_full(const bufferlist& bl);
375     void writesame(uint64_t off, uint64_t write_len,
376                    const bufferlist& bl);
377     void append(const bufferlist& bl);
378     void remove();
379     void truncate(uint64_t off);
380     void zero(uint64_t off, uint64_t len);
381     void rmxattr(const char *name);
382     void setxattr(const char *name, const bufferlist& bl);
383     void tmap_update(const bufferlist& cmdbl);
384     void tmap_put(const bufferlist& bl);
385     void selfmanaged_snap_rollback(uint64_t snapid);
386
387     /**
388      * Rollback an object to the specified snapshot id
389      *
390      * Used with pool snapshots
391      *
392      * @param snapid [in] snopshot id specified
393      */
394     void snap_rollback(uint64_t snapid);
395
396     /**
397      * set keys and values according to map
398      *
399      * @param map [in] keys and values to set
400      */
401     void omap_set(const std::map<std::string, bufferlist> &map);
402
403     /**
404      * set header
405      *
406      * @param bl [in] header to set
407      */
408     void omap_set_header(const bufferlist &bl);
409
410     /**
411      * Clears omap contents
412      */
413     void omap_clear();
414
415     /**
416      * Clears keys in to_rm
417      *
418      * @param to_rm [in] keys to remove
419      */
420     void omap_rm_keys(const std::set<std::string> &to_rm);
421
422     /**
423      * Copy an object
424      *
425      * Copies an object from another location.  The operation is atomic in that
426      * the copy either succeeds in its entirety or fails (e.g., because the
427      * source object was modified while the copy was in progress).
428      *
429      * @param src source object name
430      * @param src_ioctx ioctx for the source object
431      * @param src_version current version of the source object
432      * @param src_fadvise_flags the fadvise flags for source object
433      */
434     void copy_from(const std::string& src, const IoCtx& src_ioctx,
435                    uint64_t src_version);
436     void copy_from2(const std::string& src, const IoCtx& src_ioctx,
437                     uint64_t src_version, uint32_t src_fadvise_flags);
438
439     /**
440      * undirty an object
441      *
442      * Clear an objects dirty flag
443      */
444     void undirty();
445
446     /**
447      * Set allocation hint for an object
448      *
449      * @param expected_object_size expected size of the object, in bytes
450      * @param expected_write_size expected size of writes to the object, in bytes
451      * @param flags flags ()
452      */
453     void set_alloc_hint(uint64_t expected_object_size,
454                         uint64_t expected_write_size);
455     void set_alloc_hint2(uint64_t expected_object_size,
456                          uint64_t expected_write_size,
457                          uint32_t flags);
458
459     /**
460      * Pin/unpin an object in cache tier
461      *
462      * @returns 0 on success, negative error code on failure
463      */
464     void cache_pin();
465     void cache_unpin();
466
467     /**
468      * Extensible tier
469      *
470      * Set redirect target
471      */
472     void set_redirect(const std::string& tgt_obj, const IoCtx& tgt_ioctx,
473                       uint64_t tgt_version);
474
475     friend class IoCtx;
476   };
477
478   /*
479    * ObjectReadOperation : compound object operation that return value
480    * Batch multiple object operations into a single request, to be applied
481    * atomically.
482    */
483   class CEPH_RADOS_API ObjectReadOperation : public ObjectOperation
484   {
485   public:
486     ObjectReadOperation() {}
487     ~ObjectReadOperation() override {}
488
489     void stat(uint64_t *psize, time_t *pmtime, int *prval);
490     void stat2(uint64_t *psize, struct timespec *pts, int *prval);
491     void getxattr(const char *name, bufferlist *pbl, int *prval);
492     void getxattrs(std::map<std::string, bufferlist> *pattrs, int *prval);
493     void read(size_t off, uint64_t len, bufferlist *pbl, int *prval);
494     void checksum(rados_checksum_type_t type, const bufferlist &init_value_bl,
495                   uint64_t off, size_t len, size_t chunk_size, bufferlist *pbl,
496                   int *prval);
497
498     /**
499      * see aio_sparse_read()
500      */
501     void sparse_read(uint64_t off, uint64_t len, std::map<uint64_t,uint64_t> *m,
502                     bufferlist *data_bl, int *prval);
503     void tmap_get(bufferlist *pbl, int *prval);
504
505     /**
506      * omap_get_vals: keys and values from the object omap
507      *
508      * Get up to max_return keys and values beginning after start_after
509      *
510      * @param start_after [in] list no keys smaller than start_after
511      * @param max_return [in] list no more than max_return key/value pairs
512      * @param out_vals [out] place returned values in out_vals on completion
513      * @param prval [out] place error code in prval upon completion
514      */
515     void omap_get_vals(
516       const std::string &start_after,
517       uint64_t max_return,
518       std::map<std::string, bufferlist> *out_vals,
519       int *prval) __attribute__ ((deprecated));  // use v2
520
521     /**
522      * omap_get_vals: keys and values from the object omap
523      *
524      * Get up to max_return keys and values beginning after start_after
525      *
526      * @param start_after [in] list no keys smaller than start_after
527      * @param max_return [in] list no more than max_return key/value pairs
528      * @param out_vals [out] place returned values in out_vals on completion
529      * @param prval [out] place error code in prval upon completion
530      */
531     void omap_get_vals2(
532       const std::string &start_after,
533       uint64_t max_return,
534       std::map<std::string, bufferlist> *out_vals,
535       bool *pmore,
536       int *prval);
537
538     /**
539      * omap_get_vals: keys and values from the object omap
540      *
541      * Get up to max_return keys and values beginning after start_after
542      *
543      * @param start_after [in] list keys starting after start_after
544      * @param filter_prefix [in] list only keys beginning with filter_prefix
545      * @param max_return [in] list no more than max_return key/value pairs
546      * @param out_vals [out] place returned values in out_vals on completion
547      * @param prval [out] place error code in prval upon completion
548      */
549     void omap_get_vals(
550       const std::string &start_after,
551       const std::string &filter_prefix,
552       uint64_t max_return,
553       std::map<std::string, bufferlist> *out_vals,
554       int *prval) __attribute__ ((deprecated));  // use v2
555
556     /**
557      * omap_get_vals2: 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 keys starting after start_after
562      * @param filter_prefix [in] list only keys beginning with filter_prefix
563      * @param max_return [in] list no more than max_return key/value pairs
564      * @param out_vals [out] place returned values in out_vals on completion
565      * @param pmore [out] pointer to bool indicating whether there are more keys
566      * @param prval [out] place error code in prval upon completion
567      */
568     void omap_get_vals2(
569       const std::string &start_after,
570       const std::string &filter_prefix,
571       uint64_t max_return,
572       std::map<std::string, bufferlist> *out_vals,
573       bool *pmore,
574       int *prval);
575
576
577     /**
578      * omap_get_keys: keys from the object omap
579      *
580      * Get up to max_return keys beginning after start_after
581      *
582      * @param start_after [in] list keys starting after start_after
583      * @param max_return [in] list no more than max_return keys
584      * @param out_keys [out] place returned values in out_keys on completion
585      * @param prval [out] place error code in prval upon completion
586      */
587     void omap_get_keys(const std::string &start_after,
588                        uint64_t max_return,
589                        std::set<std::string> *out_keys,
590                        int *prval) __attribute__ ((deprecated)); // use v2
591
592     /**
593      * omap_get_keys2: keys from the object omap
594      *
595      * Get up to max_return keys beginning after start_after
596      *
597      * @param start_after [in] list keys starting after start_after
598      * @param max_return [in] list no more than max_return keys
599      * @param out_keys [out] place returned values in out_keys on completion
600      * @param pmore [out] pointer to bool indicating whether there are more keys
601      * @param prval [out] place error code in prval upon completion
602      */
603     void omap_get_keys2(const std::string &start_after,
604                         uint64_t max_return,
605                         std::set<std::string> *out_keys,
606                         bool *pmore,
607                         int *prval);
608
609     /**
610      * omap_get_header: get header from object omap
611      *
612      * @param header [out] place header here upon completion
613      * @param prval [out] place error code in prval upon completion
614      */
615     void omap_get_header(bufferlist *header, int *prval);
616
617     /**
618      * get key/value pairs for specified keys
619      *
620      * @param keys [in] keys to get
621      * @param map [out] place key/value pairs found here on completion
622      * @param prval [out] place error code in prval upon completion
623      */
624     void omap_get_vals_by_keys(const std::set<std::string> &keys,
625                                std::map<std::string, bufferlist> *map,
626                                int *prval);
627
628     /**
629      * list_watchers: Get list watchers of object
630      *
631      * @param out_watchers [out] place returned values in out_watchers on completion
632      * @param prval [out] place error code in prval upon completion
633      */
634     void list_watchers(std::list<obj_watch_t> *out_watchers, int *prval);
635
636     /**
637      * list snapshot clones associated with a logical object
638      *
639      * This will include a record for each version of the object,
640      * include the "HEAD" (which will have a cloneid of SNAP_HEAD).
641      * Each clone includes a vector of snap ids for which it is
642      * defined to exist.
643      *
644      * NOTE: this operation must be submitted from an IoCtx with a
645      * read snapid of SNAP_DIR for reliable results.
646      *
647      * @param out_snaps [out] pointer to resulting snap_set_t
648      * @param prval [out] place error code in prval upon completion
649      */
650     void list_snaps(snap_set_t *out_snaps, int *prval);
651
652     /**
653      * query dirty state of an object
654      *
655      * @param isdirty [out] pointer to resulting bool
656      * @param prval [out] place error code in prval upon completion
657      */
658     void is_dirty(bool *isdirty, int *prval);
659
660     /**
661      * flush a cache tier object to backing tier; will block racing
662      * updates.
663      *
664      * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
665      * triggering a promotion.
666      */
667     void cache_flush();
668
669     /**
670      * Flush a cache tier object to backing tier; will EAGAIN if we race
671      * with an update.  Must be used with the SKIPRWLOCKS flag.
672      *
673      * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
674      * triggering a promotion.
675      */
676     void cache_try_flush();
677
678     /**
679      * evict a clean cache tier object
680      *
681      * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
682      * triggering a promote on the OSD (that is then evicted).
683      */
684     void cache_evict();
685   };
686
687   /* IoCtx : This is a context in which we can perform I/O.
688    * It includes a Pool,
689    *
690    * Typical use (error checking omitted):
691    *
692    * IoCtx p;
693    * rados.ioctx_create("my_pool", p);
694    * p->stat(&stats);
695    * ... etc ...
696    *
697    * NOTE: be sure to call watch_flush() prior to destroying any IoCtx
698    * that is used for watch events to ensure that racing callbacks
699    * have completed.
700    */
701   class CEPH_RADOS_API IoCtx
702   {
703   public:
704     IoCtx();
705     static void from_rados_ioctx_t(rados_ioctx_t p, IoCtx &pool);
706     IoCtx(const IoCtx& rhs);
707     IoCtx& operator=(const IoCtx& rhs);
708
709     ~IoCtx();
710
711     // Close our pool handle
712     void close();
713
714     // deep copy
715     void dup(const IoCtx& rhs);
716
717     // set pool auid
718     int set_auid(uint64_t auid_);
719
720     // set pool auid
721     int set_auid_async(uint64_t auid_, PoolAsyncCompletion *c);
722
723     // get pool auid
724     int get_auid(uint64_t *auid_);
725
726     uint64_t get_instance_id() const;
727
728     std::string get_pool_name();
729
730     bool pool_requires_alignment();
731     int pool_requires_alignment2(bool * requires);
732     uint64_t pool_required_alignment();
733     int pool_required_alignment2(uint64_t * alignment);
734
735     // create an object
736     int create(const std::string& oid, bool exclusive);
737     int create(const std::string& oid, bool exclusive,
738                const std::string& category); ///< category is unused
739
740     /**
741      * write bytes to an object at a specified offset
742      *
743      * NOTE: this call steals the contents of @param bl.
744      */
745     int write(const std::string& oid, bufferlist& bl, size_t len, uint64_t off);
746     /**
747      * append bytes to an object
748      *
749      * NOTE: this call steals the contents of @param bl.
750      */
751     int append(const std::string& oid, bufferlist& bl, size_t len);
752     /**
753      * replace object contents with provided data
754      *
755      * NOTE: this call steals the contents of @param bl.
756      */
757     int write_full(const std::string& oid, bufferlist& bl);
758     int writesame(const std::string& oid, bufferlist& bl,
759                   size_t write_len, uint64_t off);
760     int read(const std::string& oid, bufferlist& bl, size_t len, uint64_t off);
761     int checksum(const std::string& o, rados_checksum_type_t type,
762                  const bufferlist &init_value_bl, size_t len, uint64_t off,
763                  size_t chunk_size, bufferlist *pbl);
764     int remove(const std::string& oid);
765     int remove(const std::string& oid, int flags);
766     int trunc(const std::string& oid, uint64_t size);
767     int mapext(const std::string& o, uint64_t off, size_t len, std::map<uint64_t,uint64_t>& m);
768     int cmpext(const std::string& o, uint64_t off, bufferlist& cmp_bl);
769     int sparse_read(const std::string& o, std::map<uint64_t,uint64_t>& m, bufferlist& bl, size_t len, uint64_t off);
770     int getxattr(const std::string& oid, const char *name, bufferlist& bl);
771     int getxattrs(const std::string& oid, std::map<std::string, bufferlist>& attrset);
772     int setxattr(const std::string& oid, const char *name, bufferlist& bl);
773     int rmxattr(const std::string& oid, const char *name);
774     int stat(const std::string& oid, uint64_t *psize, time_t *pmtime);
775     int stat2(const std::string& oid, uint64_t *psize, struct timespec *pts);
776     int exec(const std::string& oid, const char *cls, const char *method,
777              bufferlist& inbl, bufferlist& outbl);
778     /**
779      * modify object tmap based on encoded update sequence
780      *
781      * NOTE: this call steals the contents of @param bl
782      */
783     int tmap_update(const std::string& oid, bufferlist& cmdbl);
784     /**
785      * replace object contents with provided encoded tmap data
786      *
787      * NOTE: this call steals the contents of @param bl
788      */
789     int tmap_put(const std::string& oid, bufferlist& bl);
790     int tmap_get(const std::string& oid, bufferlist& bl);
791     int tmap_to_omap(const std::string& oid, bool nullok=false);
792
793     int omap_get_vals(const std::string& oid,
794                       const std::string& start_after,
795                       uint64_t max_return,
796                       std::map<std::string, bufferlist> *out_vals);
797     int omap_get_vals2(const std::string& oid,
798                        const std::string& start_after,
799                        uint64_t max_return,
800                        std::map<std::string, bufferlist> *out_vals,
801                        bool *pmore);
802     int omap_get_vals(const std::string& oid,
803                       const std::string& start_after,
804                       const std::string& filter_prefix,
805                       uint64_t max_return,
806                       std::map<std::string, bufferlist> *out_vals);
807     int omap_get_vals2(const std::string& oid,
808                        const std::string& start_after,
809                        const std::string& filter_prefix,
810                        uint64_t max_return,
811                        std::map<std::string, bufferlist> *out_vals,
812                        bool *pmore);
813     int omap_get_keys(const std::string& oid,
814                       const std::string& start_after,
815                       uint64_t max_return,
816                       std::set<std::string> *out_keys);
817     int omap_get_keys2(const std::string& oid,
818                        const std::string& start_after,
819                        uint64_t max_return,
820                        std::set<std::string> *out_keys,
821                        bool *pmore);
822     int omap_get_header(const std::string& oid,
823                         bufferlist *bl);
824     int omap_get_vals_by_keys(const std::string& oid,
825                               const std::set<std::string>& keys,
826                               std::map<std::string, bufferlist> *vals);
827     int omap_set(const std::string& oid,
828                  const std::map<std::string, bufferlist>& map);
829     int omap_set_header(const std::string& oid,
830                         const bufferlist& bl);
831     int omap_clear(const std::string& oid);
832     int omap_rm_keys(const std::string& oid,
833                      const std::set<std::string>& keys);
834
835     void snap_set_read(snap_t seq);
836     int selfmanaged_snap_set_write_ctx(snap_t seq, std::vector<snap_t>& snaps);
837
838     // Create a snapshot with a given name
839     int snap_create(const char *snapname);
840
841     // Look up a snapshot by name.
842     // Returns 0 on success; error code otherwise
843     int snap_lookup(const char *snapname, snap_t *snap);
844
845     // Gets a timestamp for a snap
846     int snap_get_stamp(snap_t snapid, time_t *t);
847
848     // Gets the name of a snap
849     int snap_get_name(snap_t snapid, std::string *s);
850
851     // Remove a snapshot from this pool
852     int snap_remove(const char *snapname);
853
854     int snap_list(std::vector<snap_t> *snaps);
855
856     int snap_rollback(const std::string& oid, const char *snapname);
857
858     // Deprecated name kept for backward compatibility - same as snap_rollback()
859     int rollback(const std::string& oid, const char *snapname)
860       __attribute__ ((deprecated));
861
862     int selfmanaged_snap_create(uint64_t *snapid);
863     void aio_selfmanaged_snap_create(uint64_t *snapid, AioCompletion *c);
864
865     int selfmanaged_snap_remove(uint64_t snapid);
866     void aio_selfmanaged_snap_remove(uint64_t snapid, AioCompletion *c);
867
868     int selfmanaged_snap_rollback(const std::string& oid, uint64_t snapid);
869
870     // Advisory locking on rados objects.
871     int lock_exclusive(const std::string &oid, const std::string &name,
872                        const std::string &cookie,
873                        const std::string &description,
874                        struct timeval * duration, uint8_t flags);
875
876     int lock_shared(const std::string &oid, const std::string &name,
877                     const std::string &cookie, const std::string &tag,
878                     const std::string &description,
879                     struct timeval * duration, uint8_t flags);
880
881     int unlock(const std::string &oid, const std::string &name,
882                const std::string &cookie);
883
884     int break_lock(const std::string &oid, const std::string &name,
885                    const std::string &client, const std::string &cookie);
886
887     int list_lockers(const std::string &oid, const std::string &name,
888                      int *exclusive,
889                      std::string *tag,
890                      std::list<librados::locker_t> *lockers);
891
892
893     /// Start enumerating objects for a pool
894     NObjectIterator nobjects_begin();
895     NObjectIterator nobjects_begin(const bufferlist &filter);
896     /// Start enumerating objects for a pool starting from a hash position
897     NObjectIterator nobjects_begin(uint32_t start_hash_position);
898     NObjectIterator nobjects_begin(uint32_t start_hash_position,
899                                    const bufferlist &filter);
900     /// Start enumerating objects for a pool starting from cursor
901     NObjectIterator nobjects_begin(const librados::ObjectCursor& cursor);
902     NObjectIterator nobjects_begin(const librados::ObjectCursor& cursor,
903                                    const bufferlist &filter);
904     /// Iterator indicating the end of a pool
905     const NObjectIterator& nobjects_end() const;
906
907     /// Get cursor for pool beginning
908     ObjectCursor object_list_begin();
909
910     /// Get cursor for pool end
911     ObjectCursor object_list_end();
912
913     /// Check whether a cursor is at the end of a pool
914     bool object_list_is_end(const ObjectCursor &oc);
915
916     /// List some objects between two cursors
917     int object_list(const ObjectCursor &start, const ObjectCursor &finish,
918                     const size_t result_count,
919                     const bufferlist &filter,
920                     std::vector<ObjectItem> *result,
921                     ObjectCursor *next);
922
923     /// Generate cursors that include the N out of Mth slice of the pool
924     void object_list_slice(
925         const ObjectCursor start,
926         const ObjectCursor finish,
927         const size_t n,
928         const size_t m,
929         ObjectCursor *split_start,
930         ObjectCursor *split_finish);
931
932     /**
933      * List available hit set objects
934      *
935      * @param uint32_t [in] hash position to query
936      * @param c [in] completion
937      * @param pls [out] list of available intervals
938      */
939     int hit_set_list(uint32_t hash, AioCompletion *c,
940                      std::list< std::pair<time_t, time_t> > *pls);
941
942     /**
943      * Retrieve hit set for a given hash, and time
944      *
945      * @param hash [in] hash position
946      * @param c [in] completion
947      * @param stamp [in] time interval that falls within the hit set's interval
948      * @param pbl [out] buffer to store the result in
949      */
950     int hit_set_get(uint32_t hash, AioCompletion *c, time_t stamp,
951                     bufferlist *pbl);
952
953     uint64_t get_last_version();
954
955     int aio_read(const std::string& oid, AioCompletion *c,
956                  bufferlist *pbl, size_t len, uint64_t off);
957     /**
958      * Asynchronously read from an object at a particular snapshot
959      *
960      * This is the same as normal aio_read, except that it chooses
961      * the snapshot to read from from its arguments instead of the
962      * internal IoCtx state.
963      *
964      * The return value of the completion will be number of bytes read on
965      * success, negative error code on failure.
966      *
967      * @param oid the name of the object to read from
968      * @param c what to do when the read is complete
969      * @param pbl where to store the results
970      * @param len the number of bytes to read
971      * @param off the offset to start reading from in the object
972      * @param snapid the id of the snapshot to read from
973      * @returns 0 on success, negative error code on failure
974      */
975     int aio_read(const std::string& oid, AioCompletion *c,
976                  bufferlist *pbl, size_t len, uint64_t off, uint64_t snapid);
977     int aio_sparse_read(const std::string& oid, AioCompletion *c,
978                         std::map<uint64_t,uint64_t> *m, bufferlist *data_bl,
979                         size_t len, uint64_t off);
980     /**
981      * Asynchronously read existing extents from an object at a
982      * particular snapshot
983      *
984      * This is the same as normal aio_sparse_read, except that it chooses
985      * the snapshot to read from from its arguments instead of the
986      * internal IoCtx state.
987      *
988      * m will be filled in with a map of extents in the object,
989      * mapping offsets to lengths (in bytes) within the range
990      * requested. The data for all of the extents are stored
991      * back-to-back in offset order in data_bl.
992      *
993      * @param oid the name of the object to read from
994      * @param c what to do when the read is complete
995      * @param m where to store the map of extents
996      * @param data_bl where to store the data
997      * @param len the number of bytes to read
998      * @param off the offset to start reading from in the object
999      * @param snapid the id of the snapshot to read from
1000      * @returns 0 on success, negative error code on failure
1001      */
1002     int aio_sparse_read(const std::string& oid, AioCompletion *c,
1003                         std::map<uint64_t,uint64_t> *m, bufferlist *data_bl,
1004                         size_t len, uint64_t off, uint64_t snapid);
1005     /**
1006      * Asynchronously compare an on-disk object range with a buffer
1007      *
1008      * @param oid the name of the object to read from
1009      * @param c what to do when the read is complete
1010      * @param off object byte offset at which to start the comparison
1011      * @param cmp_bl buffer containing bytes to be compared with object contents
1012      * @returns 0 on success, negative error code on failure,
1013      *  (-MAX_ERRNO - mismatch_off) on mismatch
1014      */
1015     int aio_cmpext(const std::string& oid,
1016                    librados::AioCompletion *c,
1017                    uint64_t off,
1018                    bufferlist& cmp_bl);
1019     int aio_write(const std::string& oid, AioCompletion *c, const bufferlist& bl,
1020                   size_t len, uint64_t off);
1021     int aio_append(const std::string& oid, AioCompletion *c, const bufferlist& bl,
1022                   size_t len);
1023     int aio_write_full(const std::string& oid, AioCompletion *c, const bufferlist& bl);
1024     int aio_writesame(const std::string& oid, AioCompletion *c, const bufferlist& bl,
1025                       size_t write_len, uint64_t off);
1026
1027     /**
1028      * Asychronously remove an object
1029      *
1030      * Queues the remove and returns.
1031      *
1032      * The return value of the completion will be 0 on success, negative
1033      * error code on failure.
1034      *
1035      * @param oid the name of the object
1036      * @param c what to do when the remove is safe and complete
1037      * @returns 0 on success, -EROFS if the io context specifies a snap_seq
1038      * other than SNAP_HEAD
1039      */
1040     int aio_remove(const std::string& oid, AioCompletion *c);
1041     int aio_remove(const std::string& oid, AioCompletion *c, int flags);
1042
1043     /**
1044      * Wait for all currently pending aio writes to be safe.
1045      *
1046      * @returns 0 on success, negative error code on failure
1047      */
1048     int aio_flush();
1049
1050     /**
1051      * Schedule a callback for when all currently pending
1052      * aio writes are safe. This is a non-blocking version of
1053      * aio_flush().
1054      *
1055      * @param c what to do when the writes are safe
1056      * @returns 0 on success, negative error code on failure
1057      */
1058     int aio_flush_async(AioCompletion *c);
1059     int aio_getxattr(const std::string& oid, AioCompletion *c, const char *name, bufferlist& bl);
1060     int aio_getxattrs(const std::string& oid, AioCompletion *c, std::map<std::string, bufferlist>& attrset);
1061     int aio_setxattr(const std::string& oid, AioCompletion *c, const char *name, bufferlist& bl);
1062     int aio_rmxattr(const std::string& oid, AioCompletion *c, const char *name);
1063     int aio_stat(const std::string& oid, AioCompletion *c, uint64_t *psize, time_t *pmtime);
1064     int aio_stat2(const std::string& oid, AioCompletion *c, uint64_t *psize, struct timespec *pts);
1065
1066     /**
1067      * Cancel aio operation
1068      *
1069      * @param c completion handle
1070      * @returns 0 on success, negative error code on failure
1071      */
1072     int aio_cancel(AioCompletion *c);
1073
1074     int aio_exec(const std::string& oid, AioCompletion *c, const char *cls, const char *method,
1075                  bufferlist& inbl, bufferlist *outbl);
1076
1077     /*
1078      * asynchronous version of unlock
1079      */
1080     int aio_unlock(const std::string &oid, const std::string &name,
1081                    const std::string &cookie, AioCompletion *c);
1082
1083     // compound object operations
1084     int operate(const std::string& oid, ObjectWriteOperation *op);
1085     int operate(const std::string& oid, ObjectReadOperation *op, bufferlist *pbl);
1086     int aio_operate(const std::string& oid, AioCompletion *c, ObjectWriteOperation *op);
1087     int aio_operate(const std::string& oid, AioCompletion *c, ObjectWriteOperation *op, int flags);
1088     /**
1089      * Schedule an async write operation with explicit snapshot parameters
1090      *
1091      * This is the same as the first aio_operate(), except that it
1092      * gets the snapshot context from its arguments instead of the
1093      * IoCtx internal state.
1094      *
1095      * @param oid the object to operate on
1096      * @param c what to do when the operation is complete and safe
1097      * @param op which operations to perform
1098      * @param seq latest selfmanaged snapshot sequence number for this object
1099      * @param snaps currently existing selfmanaged snapshot ids for this object
1100      * @returns 0 on success, negative error code on failure
1101      */
1102     int aio_operate(const std::string& oid, AioCompletion *c,
1103                     ObjectWriteOperation *op, snap_t seq,
1104                     std::vector<snap_t>& snaps);
1105     int aio_operate(const std::string& oid, AioCompletion *c,
1106         ObjectWriteOperation *op, snap_t seq,
1107         std::vector<snap_t>& snaps,
1108         const blkin_trace_info *trace_info);
1109     int aio_operate(const std::string& oid, AioCompletion *c,
1110                     ObjectReadOperation *op, bufferlist *pbl);
1111
1112     int aio_operate(const std::string& oid, AioCompletion *c,
1113                     ObjectReadOperation *op, snap_t snapid, int flags,
1114                     bufferlist *pbl)
1115       __attribute__ ((deprecated));
1116
1117     int aio_operate(const std::string& oid, AioCompletion *c,
1118                     ObjectReadOperation *op, int flags,
1119                     bufferlist *pbl);
1120     int aio_operate(const std::string& oid, AioCompletion *c,
1121         ObjectReadOperation *op, int flags,
1122         bufferlist *pbl, const blkin_trace_info *trace_info);
1123
1124     // watch/notify
1125     int watch2(const std::string& o, uint64_t *handle,
1126                librados::WatchCtx2 *ctx);
1127     int watch3(const std::string& o, uint64_t *handle,
1128                librados::WatchCtx2 *ctx, uint32_t timeout);
1129     int aio_watch(const std::string& o, AioCompletion *c, uint64_t *handle,
1130                librados::WatchCtx2 *ctx);
1131     int aio_watch2(const std::string& o, AioCompletion *c, uint64_t *handle,
1132                librados::WatchCtx2 *ctx, uint32_t timeout);
1133     int unwatch2(uint64_t handle);
1134     int aio_unwatch(uint64_t handle, AioCompletion *c);
1135     /**
1136      * Send a notify event ot watchers
1137      *
1138      * Upon completion the pbl bufferlist reply payload will be
1139      * encoded like so:
1140      *
1141      *    le32 num_acks
1142      *    {
1143      *      le64 gid     global id for the client (for client.1234 that's 1234)
1144      *      le64 cookie  cookie for the client
1145      *      le32 buflen  length of reply message buffer
1146      *      u8 * buflen  payload
1147      *    } * num_acks
1148      *    le32 num_timeouts
1149      *    {
1150      *      le64 gid     global id for the client
1151      *      le64 cookie  cookie for the client
1152      *    } * num_timeouts
1153      *
1154      *
1155      */
1156     int notify2(const std::string& o,   ///< object
1157                 bufferlist& bl,         ///< optional broadcast payload
1158                 uint64_t timeout_ms,    ///< timeout (in ms)
1159                 bufferlist *pbl);       ///< reply buffer
1160     int aio_notify(const std::string& o,   ///< object
1161                    AioCompletion *c,       ///< completion when notify completes
1162                    bufferlist& bl,         ///< optional broadcast payload
1163                    uint64_t timeout_ms,    ///< timeout (in ms)
1164                    bufferlist *pbl);       ///< reply buffer
1165
1166     int list_watchers(const std::string& o, std::list<obj_watch_t> *out_watchers);
1167     int list_snaps(const std::string& o, snap_set_t *out_snaps);
1168     void set_notify_timeout(uint32_t timeout);
1169
1170     /// acknowledge a notify we received.
1171     void notify_ack(const std::string& o, ///< watched object
1172                     uint64_t notify_id,   ///< notify id
1173                     uint64_t cookie,      ///< our watch handle
1174                     bufferlist& bl);      ///< optional reply payload
1175
1176     /***
1177      * check on watch validity
1178      *
1179      * Check if a watch is valid.  If so, return the number of
1180      * milliseconds since we last confirmed its liveness.  If there is
1181      * a known error, return it.
1182      *
1183      * If there is an error, the watch is no longer valid, and should
1184      * be destroyed with unwatch().  The the user is still interested
1185      * in the object, a new watch should be created with watch().
1186      *
1187      * @param cookie watch handle
1188      * @returns ms since last confirmed valid, or error
1189      */
1190     int watch_check(uint64_t cookie);
1191
1192     // old, deprecated versions
1193     int watch(const std::string& o, uint64_t ver, uint64_t *cookie,
1194               librados::WatchCtx *ctx) __attribute__ ((deprecated));
1195     int notify(const std::string& o, uint64_t ver, bufferlist& bl)
1196       __attribute__ ((deprecated));
1197     int unwatch(const std::string& o, uint64_t cookie)
1198       __attribute__ ((deprecated));
1199
1200     /**
1201      * Set allocation hint for an object
1202      *
1203      * This is an advisory operation, it will always succeed (as if it
1204      * was submitted with a OP_FAILOK flag set) and is not guaranteed
1205      * to do anything on the backend.
1206      *
1207      * @param o the name of the object
1208      * @param expected_object_size expected size of the object, in bytes
1209      * @param expected_write_size expected size of writes to the object, in bytes
1210      * @returns 0 on success, negative error code on failure
1211      */
1212     int set_alloc_hint(const std::string& o,
1213                        uint64_t expected_object_size,
1214                        uint64_t expected_write_size);
1215     int set_alloc_hint2(const std::string& o,
1216                         uint64_t expected_object_size,
1217                         uint64_t expected_write_size,
1218                         uint32_t flags);
1219
1220     // assert version for next sync operations
1221     void set_assert_version(uint64_t ver);
1222
1223     /**
1224      * Pin/unpin an object in cache tier
1225      *
1226      * @param o the name of the object
1227      * @returns 0 on success, negative error code on failure
1228      */
1229     int cache_pin(const std::string& o);
1230     int cache_unpin(const std::string& o);
1231
1232     std::string get_pool_name() const;
1233
1234     void locator_set_key(const std::string& key);
1235     void set_namespace(const std::string& nspace);
1236
1237     int64_t get_id();
1238
1239     // deprecated versions
1240     uint32_t get_object_hash_position(const std::string& oid)
1241       __attribute__ ((deprecated));
1242     uint32_t get_object_pg_hash_position(const std::string& oid)
1243       __attribute__ ((deprecated));
1244
1245     int get_object_hash_position2(const std::string& oid, uint32_t *hash_position);
1246     int get_object_pg_hash_position2(const std::string& oid, uint32_t *pg_hash_position);
1247
1248     config_t cct();
1249
1250     void set_osdmap_full_try();
1251     void unset_osdmap_full_try();
1252
1253     int application_enable(const std::string& app_name, bool force);
1254     int application_enable_async(const std::string& app_name,
1255                                  bool force, PoolAsyncCompletion *c);
1256     int application_list(std::set<std::string> *app_names);
1257     int application_metadata_get(const std::string& app_name,
1258                                  const std::string &key,
1259                                  std::string *value);
1260     int application_metadata_set(const std::string& app_name,
1261                                  const std::string &key,
1262                                  const std::string& value);
1263     int application_metadata_remove(const std::string& app_name,
1264                                     const std::string &key);
1265     int application_metadata_list(const std::string& app_name,
1266                                   std::map<std::string, std::string> *values);
1267
1268   private:
1269     /* You can only get IoCtx instances from Rados */
1270     IoCtx(IoCtxImpl *io_ctx_impl_);
1271
1272     friend class Rados; // Only Rados can use our private constructor to create IoCtxes.
1273     friend class libradosstriper::RadosStriper; // Striper needs to see our IoCtxImpl
1274     friend class ObjectWriteOperation;  // copy_from needs to see our IoCtxImpl
1275
1276     IoCtxImpl *io_ctx_impl;
1277   };
1278
1279   struct PlacementGroupImpl;
1280   struct CEPH_RADOS_API PlacementGroup {
1281     PlacementGroup();
1282     PlacementGroup(const PlacementGroup&);
1283     ~PlacementGroup();
1284     bool parse(const char*);
1285     std::unique_ptr<PlacementGroupImpl> impl;
1286   };
1287
1288   CEPH_RADOS_API std::ostream& operator<<(std::ostream&, const PlacementGroup&);
1289
1290   class CEPH_RADOS_API Rados
1291   {
1292   public:
1293     static void version(int *major, int *minor, int *extra);
1294
1295     Rados();
1296     explicit Rados(IoCtx& ioctx);
1297     ~Rados();
1298
1299     int init(const char * const id);
1300     int init2(const char * const name, const char * const clustername,
1301               uint64_t flags);
1302     int init_with_context(config_t cct_);
1303     config_t cct();
1304     int connect();
1305     void shutdown();
1306     int watch_flush();
1307     int aio_watch_flush(AioCompletion*);
1308     int conf_read_file(const char * const path) const;
1309     int conf_parse_argv(int argc, const char ** argv) const;
1310     int conf_parse_argv_remainder(int argc, const char ** argv,
1311                                   const char ** remargv) const;
1312     int conf_parse_env(const char *env) const;
1313     int conf_set(const char *option, const char *value);
1314     int conf_get(const char *option, std::string &val);
1315
1316     int service_daemon_register(
1317       const std::string& service,  ///< service name (e.g., 'rgw')
1318       const std::string& name,     ///< daemon name (e.g., 'gwfoo')
1319       const std::map<std::string,std::string>& metadata); ///< static metadata about daemon
1320     int service_daemon_update_status(
1321       const std::map<std::string,std::string>& status);
1322
1323     int pool_create(const char *name);
1324     int pool_create(const char *name, uint64_t auid);
1325     int pool_create(const char *name, uint64_t auid, uint8_t crush_rule);
1326     int pool_create_async(const char *name, PoolAsyncCompletion *c);
1327     int pool_create_async(const char *name, uint64_t auid, PoolAsyncCompletion *c);
1328     int pool_create_async(const char *name, uint64_t auid, uint8_t crush_rule, PoolAsyncCompletion *c);
1329     int pool_get_base_tier(int64_t pool, int64_t* base_tier);
1330     int pool_delete(const char *name);
1331     int pool_delete_async(const char *name, PoolAsyncCompletion *c);
1332     int64_t pool_lookup(const char *name);
1333     int pool_reverse_lookup(int64_t id, std::string *name);
1334
1335     uint64_t get_instance_id();
1336
1337     int mon_command(std::string cmd, const bufferlist& inbl,
1338                     bufferlist *outbl, std::string *outs);
1339     int mgr_command(std::string cmd, const bufferlist& inbl,
1340                     bufferlist *outbl, std::string *outs);
1341     int osd_command(int osdid, std::string cmd, const bufferlist& inbl,
1342                     bufferlist *outbl, std::string *outs);
1343     int pg_command(const char *pgstr, std::string cmd, const bufferlist& inbl,
1344                    bufferlist *outbl, std::string *outs);
1345
1346     int ioctx_create(const char *name, IoCtx &pioctx);
1347     int ioctx_create2(int64_t pool_id, IoCtx &pioctx);
1348
1349     // Features useful for test cases
1350     void test_blacklist_self(bool set);
1351
1352     /* pool info */
1353     int pool_list(std::list<std::string>& v);
1354     int pool_list2(std::list<std::pair<int64_t, std::string> >& v);
1355     int get_pool_stats(std::list<std::string>& v,
1356                        stats_map& result);
1357     /// deprecated; use simpler form.  categories no longer supported.
1358     int get_pool_stats(std::list<std::string>& v,
1359                        std::map<std::string, stats_map>& stats);
1360     /// deprecated; categories no longer supported
1361     int get_pool_stats(std::list<std::string>& v,
1362                        std::string& category,
1363                        std::map<std::string, stats_map>& stats);
1364     /// check if pool has selfmanaged snaps
1365     bool get_pool_is_selfmanaged_snaps_mode(const std::string& poolname);
1366
1367     int cluster_stat(cluster_stat_t& result);
1368     int cluster_fsid(std::string *fsid);
1369
1370     /**
1371      * List inconsistent placement groups in the given pool
1372      *
1373      * @param pool_id the pool id
1374      * @param pgs [out] the inconsistent PGs
1375      */
1376     int get_inconsistent_pgs(int64_t pool_id,
1377                              std::vector<PlacementGroup>* pgs);
1378     /**
1379      * List the inconsistent objects found in a given PG by last scrub
1380      *
1381      * @param pg the placement group returned by @c pg_list()
1382      * @param start_after the first returned @c objects
1383      * @param max_return the max number of the returned @c objects
1384      * @param c what to do when the operation is complete and safe
1385      * @param objects [out] the objects where inconsistencies are found
1386      * @param interval [in,out] an epoch indicating current interval
1387      * @returns if a non-zero @c interval is specified, will return -EAGAIN i
1388      *          the current interval begin epoch is different.
1389      */
1390     int get_inconsistent_objects(const PlacementGroup& pg,
1391                                  const object_id_t &start_after,
1392                                  unsigned max_return,
1393                                  AioCompletion *c,
1394                                  std::vector<inconsistent_obj_t>* objects,
1395                                  uint32_t* interval);
1396     /**
1397      * List the inconsistent snapsets found in a given PG by last scrub
1398      *
1399      * @param pg the placement group returned by @c pg_list()
1400      * @param start_after the first returned @c objects
1401      * @param max_return the max number of the returned @c objects
1402      * @param c what to do when the operation is complete and safe
1403      * @param snapsets [out] the objects where inconsistencies are found
1404      * @param interval [in,out] an epoch indicating current interval
1405      * @returns if a non-zero @c interval is specified, will return -EAGAIN i
1406      *          the current interval begin epoch is different.
1407      */
1408     int get_inconsistent_snapsets(const PlacementGroup& pg,
1409                                   const object_id_t &start_after,
1410                                   unsigned max_return,
1411                                   AioCompletion *c,
1412                                   std::vector<inconsistent_snapset_t>* snapset,
1413                                   uint32_t* interval);
1414
1415     /// get/wait for the most recent osdmap
1416     int wait_for_latest_osdmap();
1417
1418     int blacklist_add(const std::string& client_address,
1419                       uint32_t expire_seconds);
1420
1421     /*
1422      * pool aio
1423      *
1424      * It is up to the caller to release the completion handler, even if the pool_create_async()
1425      * and/or pool_delete_async() fails and does not send the async request
1426      */
1427     static PoolAsyncCompletion *pool_async_create_completion();
1428
1429    // -- aio --
1430     static AioCompletion *aio_create_completion();
1431     static AioCompletion *aio_create_completion(void *cb_arg, callback_t cb_complete,
1432                                                 callback_t cb_safe);
1433     
1434     friend std::ostream& operator<<(std::ostream &oss, const Rados& r);
1435   private:
1436     // We don't allow assignment or copying
1437     Rados(const Rados& rhs);
1438     const Rados& operator=(const Rados& rhs);
1439     RadosClient *client;
1440   };
1441 }
1442
1443 #endif
1444