15 #include "rados_types.hpp"
17 namespace libradosstriper
24 using ceph::bufferlist;
26 struct AioCompletionImpl;
29 class ObjectOperationImpl;
31 struct PoolAsyncCompletionImpl;
33 struct ListObjectImpl;
34 class NObjectIteratorImpl;
36 typedef void *list_ctx_t;
37 typedef uint64_t auid_t;
38 typedef void *config_t;
40 typedef struct rados_cluster_stat_t cluster_stat_t;
41 typedef struct rados_pool_stat_t pool_stat_t;
49 typedef std::map<std::string, pool_stat_t> stats_map;
51 typedef void *completion_t;
52 typedef void (*callback_t)(completion_t cb, void *arg);
54 class CEPH_RADOS_API ListObject
57 const std::string& get_nspace() const;
58 const std::string& get_oid() const;
59 const std::string& get_locator() const;
63 ListObject( const ListObject&);
64 ListObject& operator=(const ListObject& rhs);
66 ListObject(ListObjectImpl *impl);
68 friend class NObjectIteratorImpl;
69 friend std::ostream& operator<<(std::ostream& out, const ListObject& lop);
73 CEPH_RADOS_API std::ostream& operator<<(std::ostream& out, const librados::ListObject& lop);
75 class CEPH_RADOS_API NObjectIterator;
77 class CEPH_RADOS_API ObjectCursor
81 ObjectCursor(const ObjectCursor &rhs);
82 explicit ObjectCursor(rados_object_list_cursor c);
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);
90 friend class NObjectIteratorImpl;
91 friend std::ostream& operator<<(std::ostream& os, const librados::ObjectCursor& oc);
93 std::string to_str() const;
94 bool from_str(const std::string& s);
97 rados_object_list_cursor c_cursor;
99 CEPH_RADOS_API std::ostream& operator<<(std::ostream& os, const librados::ObjectCursor& oc);
101 class CEPH_RADOS_API NObjectIterator : public std::iterator <std::forward_iterator_tag, ListObject> {
103 static const NObjectIterator __EndObjectIterator;
104 NObjectIterator(): impl(NULL) {}
106 NObjectIterator(const NObjectIterator &rhs);
107 NObjectIterator& operator=(const NObjectIterator& rhs);
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
116 friend class NObjectIteratorImpl;
118 /// get current hash position of the iterator, rounded to the current pg
119 uint32_t get_pg_hash_position() const;
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);
124 /// move the iterator to a given cursor position
125 uint32_t seek(const ObjectCursor& cursor);
127 /// get current cursor position
128 ObjectCursor get_cursor();
131 * Configure PGLS filter to be applied OSD-side (requires caller
132 * to know/understand the format expected by the OSD)
134 void set_filter(const bufferlist &bl);
137 NObjectIterator(ObjListCtx *ctx_);
139 NObjectIteratorImpl *impl;
142 class CEPH_RADOS_API ObjectItem
150 /// DEPRECATED; do not use
151 class CEPH_RADOS_API WatchCtx {
154 virtual void notify(uint8_t opcode, uint64_t ver, bufferlist& bl) = 0;
157 class CEPH_RADOS_API WatchCtx2 {
159 virtual ~WatchCtx2();
161 * Callback activated when we receive a notify event.
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)
168 virtual void handle_notify(uint64_t notify_id,
170 uint64_t notifier_id,
174 * Callback activated when we encounter an error with the watch.
177 * -ENOTCONN : our watch was disconnected
178 * -ETIMEDOUT : our watch is still valid, but we may have missed
181 * @param cookie the watcher with the problem
184 virtual void handle_error(uint64_t cookie, int err) = 0;
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();
193 int wait_for_complete_and_cb();
194 int wait_for_safe_and_cb();
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();
203 AioCompletionImpl *pc;
206 struct CEPH_RADOS_API PoolAsyncCompletion {
207 PoolAsyncCompletion(PoolAsyncCompletionImpl *pc_) : pc(pc_) {}
208 int set_callback(void *cb_arg, callback_t cb);
211 int get_return_value();
213 PoolAsyncCompletionImpl *pc;
217 * These are per-op flags which may be different among
218 * ops added to an ObjectOperation.
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,
230 class CEPH_RADOS_API ObjectOperationCompletion {
232 virtual ~ObjectOperationCompletion() {}
233 virtual void handle_completion(int r, bufferlist& outbl) = 0;
237 * These flags apply to the ObjectOperation as a whole.
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.
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.
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
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.
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
267 OPERATION_FULL_TRY = LIBRADOS_OPERATION_FULL_TRY,
269 OPERATION_FULL_FORCE = LIBRADOS_OPERATION_FULL_FORCE,
273 * Alloc hint flags for the alloc_hint operation.
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,
289 * ObjectOperation : compound object operation
290 * Batch multiple object operations into a single request, to be applied
293 class CEPH_RADOS_API ObjectOperation
297 virtual ~ObjectOperation();
300 void set_op_flags(ObjectOperationFlags flags) __attribute__((deprecated));
301 //flag mean ObjectOperationFlags
302 void set_op_flags2(int flags);
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);
311 * Guard operation with a check that object version == ver
313 * @param ver [in] version to check
315 void assert_version(uint64_t ver);
318 * Guard operatation with a check that the object already exists
320 void assert_exists();
323 * get key/value pairs for specified keys
325 * @param assertions [in] comparison assertions
326 * @param prval [out] place error code in prval upon completion
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].
331 * That is, to assert that the value at key 'foo' is greater than 'bar':
333 * ObjectReadOperation op;
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);
341 const std::map<std::string, std::pair<bufferlist, int> > &assertions,
345 ObjectOperationImpl *impl;
346 ObjectOperation(const ObjectOperation& rhs);
347 ObjectOperation& operator=(const ObjectOperation& rhs);
353 * ObjectWriteOperation : compound object write operation
354 * Batch multiple object operations into a single request, to be applied
357 class CEPH_RADOS_API ObjectWriteOperation : public ObjectOperation
362 ObjectWriteOperation() : unused(NULL) {}
363 ~ObjectWriteOperation() override {}
365 void mtime(time_t *pt);
366 void mtime2(struct timespec *pts);
368 void create(bool exclusive);
369 void create(bool exclusive,
370 const std::string& category); ///< NOTE: category is unused
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);
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);
387 * Rollback an object to the specified snapshot id
389 * Used with pool snapshots
391 * @param snapid [in] snopshot id specified
393 void snap_rollback(uint64_t snapid);
396 * set keys and values according to map
398 * @param map [in] keys and values to set
400 void omap_set(const std::map<std::string, bufferlist> &map);
405 * @param bl [in] header to set
407 void omap_set_header(const bufferlist &bl);
410 * Clears omap contents
415 * Clears keys in to_rm
417 * @param to_rm [in] keys to remove
419 void omap_rm_keys(const std::set<std::string> &to_rm);
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).
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
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);
441 * Clear an objects dirty flag
446 * Set allocation hint for an object
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 ()
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,
459 * Pin/unpin an object in cache tier
461 * @returns 0 on success, negative error code on failure
470 * ObjectReadOperation : compound object operation that return value
471 * Batch multiple object operations into a single request, to be applied
474 class CEPH_RADOS_API ObjectReadOperation : public ObjectOperation
477 ObjectReadOperation() {}
478 ~ObjectReadOperation() override {}
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,
490 * see aio_sparse_read()
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);
497 * omap_get_vals: keys and values from the object omap
499 * Get up to max_return keys and values beginning after start_after
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
507 const std::string &start_after,
509 std::map<std::string, bufferlist> *out_vals,
510 int *prval) __attribute__ ((deprecated)); // use v2
513 * omap_get_vals: keys and values from the object omap
515 * Get up to max_return keys and values beginning after start_after
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
523 const std::string &start_after,
525 std::map<std::string, bufferlist> *out_vals,
530 * omap_get_vals: keys and values from the object omap
532 * Get up to max_return keys and values beginning after start_after
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
541 const std::string &start_after,
542 const std::string &filter_prefix,
544 std::map<std::string, bufferlist> *out_vals,
545 int *prval) __attribute__ ((deprecated)); // use v2
548 * omap_get_vals2: keys and values from the object omap
550 * Get up to max_return keys and values beginning after start_after
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
560 const std::string &start_after,
561 const std::string &filter_prefix,
563 std::map<std::string, bufferlist> *out_vals,
569 * omap_get_keys: keys from the object omap
571 * Get up to max_return keys beginning after start_after
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
578 void omap_get_keys(const std::string &start_after,
580 std::set<std::string> *out_keys,
581 int *prval) __attribute__ ((deprecated)); // use v2
584 * omap_get_keys2: keys from the object omap
586 * Get up to max_return keys beginning after start_after
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
594 void omap_get_keys2(const std::string &start_after,
596 std::set<std::string> *out_keys,
601 * omap_get_header: get header from object omap
603 * @param header [out] place header here upon completion
604 * @param prval [out] place error code in prval upon completion
606 void omap_get_header(bufferlist *header, int *prval);
609 * get key/value pairs for specified keys
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
615 void omap_get_vals_by_keys(const std::set<std::string> &keys,
616 std::map<std::string, bufferlist> *map,
620 * list_watchers: Get list watchers of object
622 * @param out_watchers [out] place returned values in out_watchers on completion
623 * @param prval [out] place error code in prval upon completion
625 void list_watchers(std::list<obj_watch_t> *out_watchers, int *prval);
628 * list snapshot clones associated with a logical object
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
635 * NOTE: this operation must be submitted from an IoCtx with a
636 * read snapid of SNAP_DIR for reliable results.
638 * @param out_snaps [out] pointer to resulting snap_set_t
639 * @param prval [out] place error code in prval upon completion
641 void list_snaps(snap_set_t *out_snaps, int *prval);
644 * query dirty state of an object
646 * @param isdirty [out] pointer to resulting bool
647 * @param prval [out] place error code in prval upon completion
649 void is_dirty(bool *isdirty, int *prval);
652 * flush a cache tier object to backing tier; will block racing
655 * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
656 * triggering a promotion.
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.
664 * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
665 * triggering a promotion.
667 void cache_try_flush();
670 * evict a clean cache tier object
672 * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
673 * triggering a promote on the OSD (that is then evicted).
678 /* IoCtx : This is a context in which we can perform I/O.
679 * It includes a Pool,
681 * Typical use (error checking omitted):
684 * rados.ioctx_create("my_pool", p);
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
692 class CEPH_RADOS_API 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);
702 // Close our pool handle
706 void dup(const IoCtx& rhs);
709 int set_auid(uint64_t auid_);
712 int set_auid_async(uint64_t auid_, PoolAsyncCompletion *c);
715 int get_auid(uint64_t *auid_);
717 uint64_t get_instance_id() const;
719 std::string get_pool_name();
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);
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
732 * write bytes to an object at a specified offset
734 * NOTE: this call steals the contents of @param bl.
736 int write(const std::string& oid, bufferlist& bl, size_t len, uint64_t off);
738 * append bytes to an object
740 * NOTE: this call steals the contents of @param bl.
742 int append(const std::string& oid, bufferlist& bl, size_t len);
744 * replace object contents with provided data
746 * NOTE: this call steals the contents of @param bl.
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);
770 * modify object tmap based on encoded update sequence
772 * NOTE: this call steals the contents of @param bl
774 int tmap_update(const std::string& oid, bufferlist& cmdbl);
776 * replace object contents with provided encoded tmap data
778 * NOTE: this call steals the contents of @param bl
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);
784 int omap_get_vals(const std::string& oid,
785 const std::string& start_after,
787 std::map<std::string, bufferlist> *out_vals);
788 int omap_get_vals2(const std::string& oid,
789 const std::string& start_after,
791 std::map<std::string, bufferlist> *out_vals,
793 int omap_get_vals(const std::string& oid,
794 const std::string& start_after,
795 const std::string& filter_prefix,
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,
802 std::map<std::string, bufferlist> *out_vals,
804 int omap_get_keys(const std::string& oid,
805 const std::string& start_after,
807 std::set<std::string> *out_keys);
808 int omap_get_keys2(const std::string& oid,
809 const std::string& start_after,
811 std::set<std::string> *out_keys,
813 int omap_get_header(const std::string& oid,
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);
826 void snap_set_read(snap_t seq);
827 int selfmanaged_snap_set_write_ctx(snap_t seq, std::vector<snap_t>& snaps);
829 // Create a snapshot with a given name
830 int snap_create(const char *snapname);
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);
836 // Gets a timestamp for a snap
837 int snap_get_stamp(snap_t snapid, time_t *t);
839 // Gets the name of a snap
840 int snap_get_name(snap_t snapid, std::string *s);
842 // Remove a snapshot from this pool
843 int snap_remove(const char *snapname);
845 int snap_list(std::vector<snap_t> *snaps);
847 int snap_rollback(const std::string& oid, const char *snapname);
849 // Deprecated name kept for backward compatibility - same as snap_rollback()
850 int rollback(const std::string& oid, const char *snapname)
851 __attribute__ ((deprecated));
853 int selfmanaged_snap_create(uint64_t *snapid);
854 void aio_selfmanaged_snap_create(uint64_t *snapid, AioCompletion *c);
856 int selfmanaged_snap_remove(uint64_t snapid);
857 void aio_selfmanaged_snap_remove(uint64_t snapid, AioCompletion *c);
859 int selfmanaged_snap_rollback(const std::string& oid, uint64_t snapid);
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);
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);
872 int unlock(const std::string &oid, const std::string &name,
873 const std::string &cookie);
875 int break_lock(const std::string &oid, const std::string &name,
876 const std::string &client, const std::string &cookie);
878 int list_lockers(const std::string &oid, const std::string &name,
881 std::list<librados::locker_t> *lockers);
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;
898 /// Get cursor for pool beginning
899 ObjectCursor object_list_begin();
901 /// Get cursor for pool end
902 ObjectCursor object_list_end();
904 /// Check whether a cursor is at the end of a pool
905 bool object_list_is_end(const ObjectCursor &oc);
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,
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,
920 ObjectCursor *split_start,
921 ObjectCursor *split_finish);
924 * List available hit set objects
926 * @param uint32_t [in] hash position to query
927 * @param c [in] completion
928 * @param pls [out] list of available intervals
930 int hit_set_list(uint32_t hash, AioCompletion *c,
931 std::list< std::pair<time_t, time_t> > *pls);
934 * Retrieve hit set for a given hash, and time
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
941 int hit_set_get(uint32_t hash, AioCompletion *c, time_t stamp,
944 uint64_t get_last_version();
946 int aio_read(const std::string& oid, AioCompletion *c,
947 bufferlist *pbl, size_t len, uint64_t off);
949 * Asynchronously read from an object at a particular snapshot
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.
955 * The return value of the completion will be number of bytes read on
956 * success, negative error code on failure.
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
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);
972 * Asynchronously read existing extents from an object at a
973 * particular snapshot
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.
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.
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
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);
997 * Asynchronously compare an on-disk object range with a buffer
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
1006 int aio_cmpext(const std::string& oid,
1007 librados::AioCompletion *c,
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,
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);
1019 * Asychronously remove an object
1021 * Queues the remove and returns.
1023 * The return value of the completion will be 0 on success, negative
1024 * error code on failure.
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
1031 int aio_remove(const std::string& oid, AioCompletion *c);
1032 int aio_remove(const std::string& oid, AioCompletion *c, int flags);
1035 * Wait for all currently pending aio writes to be safe.
1037 * @returns 0 on success, negative error code on failure
1042 * Schedule a callback for when all currently pending
1043 * aio writes are safe. This is a non-blocking version of
1046 * @param c what to do when the writes are safe
1047 * @returns 0 on success, negative error code on failure
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);
1058 * Cancel aio operation
1060 * @param c completion handle
1061 * @returns 0 on success, negative error code on failure
1063 int aio_cancel(AioCompletion *c);
1065 int aio_exec(const std::string& oid, AioCompletion *c, const char *cls, const char *method,
1066 bufferlist& inbl, bufferlist *outbl);
1069 * asynchronous version of unlock
1071 int aio_unlock(const std::string &oid, const std::string &name,
1072 const std::string &cookie, AioCompletion *c);
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);
1080 * Schedule an async write operation with explicit snapshot parameters
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.
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
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);
1103 int aio_operate(const std::string& oid, AioCompletion *c,
1104 ObjectReadOperation *op, snap_t snapid, int flags,
1106 __attribute__ ((deprecated));
1108 int aio_operate(const std::string& oid, AioCompletion *c,
1109 ObjectReadOperation *op, int flags,
1111 int aio_operate(const std::string& oid, AioCompletion *c,
1112 ObjectReadOperation *op, int flags,
1113 bufferlist *pbl, const blkin_trace_info *trace_info);
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);
1127 * Send a notify event ot watchers
1129 * Upon completion the pbl bufferlist reply payload will be
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
1141 * le64 gid global id for the client
1142 * le64 cookie cookie for the client
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
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);
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
1168 * check on watch validity
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.
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().
1178 * @param cookie watch handle
1179 * @returns ms since last confirmed valid, or error
1181 int watch_check(uint64_t cookie);
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));
1192 * Set allocation hint for an object
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.
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
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,
1211 // assert version for next sync operations
1212 void set_assert_version(uint64_t ver);
1215 * Pin/unpin an object in cache tier
1217 * @param o the name of the object
1218 * @returns 0 on success, negative error code on failure
1220 int cache_pin(const std::string& o);
1221 int cache_unpin(const std::string& o);
1223 std::string get_pool_name() const;
1225 void locator_set_key(const std::string& key);
1226 void set_namespace(const std::string& nspace);
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));
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);
1241 void set_osdmap_full_try();
1242 void unset_osdmap_full_try();
1245 /* You can only get IoCtx instances from Rados */
1246 IoCtx(IoCtxImpl *io_ctx_impl_);
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
1252 IoCtxImpl *io_ctx_impl;
1255 struct PlacementGroupImpl;
1256 struct CEPH_RADOS_API PlacementGroup {
1258 PlacementGroup(const PlacementGroup&);
1260 bool parse(const char*);
1261 std::unique_ptr<PlacementGroupImpl> impl;
1264 CEPH_RADOS_API std::ostream& operator<<(std::ostream&, const PlacementGroup&);
1266 class CEPH_RADOS_API Rados
1269 static void version(int *major, int *minor, int *extra);
1272 explicit Rados(IoCtx& ioctx);
1275 int init(const char * const id);
1276 int init2(const char * const name, const char * const clustername,
1278 int init_with_context(config_t cct_);
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);
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);
1304 uint64_t get_instance_id();
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);
1315 int ioctx_create(const char *name, IoCtx &pioctx);
1316 int ioctx_create2(int64_t pool_id, IoCtx &pioctx);
1318 // Features useful for test cases
1319 void test_blacklist_self(bool set);
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,
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);
1336 int cluster_stat(cluster_stat_t& result);
1337 int cluster_fsid(std::string *fsid);
1340 * List inconsistent placement groups in the given pool
1342 * @param pool_id the pool id
1343 * @param pgs [out] the inconsistent PGs
1345 int get_inconsistent_pgs(int64_t pool_id,
1346 std::vector<PlacementGroup>* pgs);
1348 * List the inconsistent objects found in a given PG by last scrub
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.
1359 int get_inconsistent_objects(const PlacementGroup& pg,
1360 const object_id_t &start_after,
1361 unsigned max_return,
1363 std::vector<inconsistent_obj_t>* objects,
1364 uint32_t* interval);
1366 * List the inconsistent snapsets found in a given PG by last scrub
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.
1377 int get_inconsistent_snapsets(const PlacementGroup& pg,
1378 const object_id_t &start_after,
1379 unsigned max_return,
1381 std::vector<inconsistent_snapset_t>* snapset,
1382 uint32_t* interval);
1384 /// get/wait for the most recent osdmap
1385 int wait_for_latest_osdmap();
1387 int blacklist_add(const std::string& client_address,
1388 uint32_t expire_seconds);
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
1396 static PoolAsyncCompletion *pool_async_create_completion();
1399 static AioCompletion *aio_create_completion();
1400 static AioCompletion *aio_create_completion(void *cb_arg, callback_t cb_complete,
1401 callback_t cb_safe);
1403 friend std::ostream& operator<<(std::ostream &oss, const Rados& r);
1405 // We don't allow assignment or copying
1406 Rados(const Rados& rhs);
1407 const Rados& operator=(const Rados& rhs);
1408 RadosClient *client;