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,
270 OPERATION_IGNORE_REDIRECT = LIBRADOS_OPERATION_IGNORE_REDIRECT,
274 * Alloc hint flags for the alloc_hint operation.
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,
290 * ObjectOperation : compound object operation
291 * Batch multiple object operations into a single request, to be applied
294 class CEPH_RADOS_API ObjectOperation
298 virtual ~ObjectOperation();
301 void set_op_flags(ObjectOperationFlags flags) __attribute__((deprecated));
302 //flag mean ObjectOperationFlags
303 void set_op_flags2(int flags);
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);
312 * Guard operation with a check that object version == ver
314 * @param ver [in] version to check
316 void assert_version(uint64_t ver);
319 * Guard operatation with a check that the object already exists
321 void assert_exists();
324 * get key/value pairs for specified keys
326 * @param assertions [in] comparison assertions
327 * @param prval [out] place error code in prval upon completion
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].
332 * That is, to assert that the value at key 'foo' is greater than 'bar':
334 * ObjectReadOperation op;
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);
342 const std::map<std::string, std::pair<bufferlist, int> > &assertions,
346 ObjectOperationImpl *impl;
347 ObjectOperation(const ObjectOperation& rhs);
348 ObjectOperation& operator=(const ObjectOperation& rhs);
354 * ObjectWriteOperation : compound object write operation
355 * Batch multiple object operations into a single request, to be applied
358 class CEPH_RADOS_API ObjectWriteOperation : public ObjectOperation
363 ObjectWriteOperation() : unused(NULL) {}
364 ~ObjectWriteOperation() override {}
366 void mtime(time_t *pt);
367 void mtime2(struct timespec *pts);
369 void create(bool exclusive);
370 void create(bool exclusive,
371 const std::string& category); ///< NOTE: category is unused
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);
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);
388 * Rollback an object to the specified snapshot id
390 * Used with pool snapshots
392 * @param snapid [in] snopshot id specified
394 void snap_rollback(uint64_t snapid);
397 * set keys and values according to map
399 * @param map [in] keys and values to set
401 void omap_set(const std::map<std::string, bufferlist> &map);
406 * @param bl [in] header to set
408 void omap_set_header(const bufferlist &bl);
411 * Clears omap contents
416 * Clears keys in to_rm
418 * @param to_rm [in] keys to remove
420 void omap_rm_keys(const std::set<std::string> &to_rm);
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).
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
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);
442 * Clear an objects dirty flag
447 * Set allocation hint for an object
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 ()
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,
460 * Pin/unpin an object in cache tier
462 * @returns 0 on success, negative error code on failure
470 * Set redirect target
472 void set_redirect(const std::string& tgt_obj, const IoCtx& tgt_ioctx,
473 uint64_t tgt_version);
479 * ObjectReadOperation : compound object operation that return value
480 * Batch multiple object operations into a single request, to be applied
483 class CEPH_RADOS_API ObjectReadOperation : public ObjectOperation
486 ObjectReadOperation() {}
487 ~ObjectReadOperation() override {}
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,
499 * see aio_sparse_read()
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);
506 * omap_get_vals: keys and values from the object omap
508 * Get up to max_return keys and values beginning after start_after
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
516 const std::string &start_after,
518 std::map<std::string, bufferlist> *out_vals,
519 int *prval) __attribute__ ((deprecated)); // use v2
522 * omap_get_vals: keys and values from the object omap
524 * Get up to max_return keys and values beginning after start_after
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
532 const std::string &start_after,
534 std::map<std::string, bufferlist> *out_vals,
539 * omap_get_vals: keys and values from the object omap
541 * Get up to max_return keys and values beginning after start_after
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
550 const std::string &start_after,
551 const std::string &filter_prefix,
553 std::map<std::string, bufferlist> *out_vals,
554 int *prval) __attribute__ ((deprecated)); // use v2
557 * omap_get_vals2: keys and values from the object omap
559 * Get up to max_return keys and values beginning after start_after
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
569 const std::string &start_after,
570 const std::string &filter_prefix,
572 std::map<std::string, bufferlist> *out_vals,
578 * omap_get_keys: keys from the object omap
580 * Get up to max_return keys beginning after start_after
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
587 void omap_get_keys(const std::string &start_after,
589 std::set<std::string> *out_keys,
590 int *prval) __attribute__ ((deprecated)); // use v2
593 * omap_get_keys2: keys from the object omap
595 * Get up to max_return keys beginning after start_after
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
603 void omap_get_keys2(const std::string &start_after,
605 std::set<std::string> *out_keys,
610 * omap_get_header: get header from object omap
612 * @param header [out] place header here upon completion
613 * @param prval [out] place error code in prval upon completion
615 void omap_get_header(bufferlist *header, int *prval);
618 * get key/value pairs for specified keys
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
624 void omap_get_vals_by_keys(const std::set<std::string> &keys,
625 std::map<std::string, bufferlist> *map,
629 * list_watchers: Get list watchers of object
631 * @param out_watchers [out] place returned values in out_watchers on completion
632 * @param prval [out] place error code in prval upon completion
634 void list_watchers(std::list<obj_watch_t> *out_watchers, int *prval);
637 * list snapshot clones associated with a logical object
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
644 * NOTE: this operation must be submitted from an IoCtx with a
645 * read snapid of SNAP_DIR for reliable results.
647 * @param out_snaps [out] pointer to resulting snap_set_t
648 * @param prval [out] place error code in prval upon completion
650 void list_snaps(snap_set_t *out_snaps, int *prval);
653 * query dirty state of an object
655 * @param isdirty [out] pointer to resulting bool
656 * @param prval [out] place error code in prval upon completion
658 void is_dirty(bool *isdirty, int *prval);
661 * flush a cache tier object to backing tier; will block racing
664 * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
665 * triggering a promotion.
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.
673 * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
674 * triggering a promotion.
676 void cache_try_flush();
679 * evict a clean cache tier object
681 * This should be used in concert with OPERATION_IGNORE_CACHE to avoid
682 * triggering a promote on the OSD (that is then evicted).
687 /* IoCtx : This is a context in which we can perform I/O.
688 * It includes a Pool,
690 * Typical use (error checking omitted):
693 * rados.ioctx_create("my_pool", p);
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
701 class CEPH_RADOS_API 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);
711 // Close our pool handle
715 void dup(const IoCtx& rhs);
718 int set_auid(uint64_t auid_);
721 int set_auid_async(uint64_t auid_, PoolAsyncCompletion *c);
724 int get_auid(uint64_t *auid_);
726 uint64_t get_instance_id() const;
728 std::string get_pool_name();
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);
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
741 * write bytes to an object at a specified offset
743 * NOTE: this call steals the contents of @param bl.
745 int write(const std::string& oid, bufferlist& bl, size_t len, uint64_t off);
747 * append bytes to an object
749 * NOTE: this call steals the contents of @param bl.
751 int append(const std::string& oid, bufferlist& bl, size_t len);
753 * replace object contents with provided data
755 * NOTE: this call steals the contents of @param bl.
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);
779 * modify object tmap based on encoded update sequence
781 * NOTE: this call steals the contents of @param bl
783 int tmap_update(const std::string& oid, bufferlist& cmdbl);
785 * replace object contents with provided encoded tmap data
787 * NOTE: this call steals the contents of @param bl
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);
793 int omap_get_vals(const std::string& oid,
794 const std::string& start_after,
796 std::map<std::string, bufferlist> *out_vals);
797 int omap_get_vals2(const std::string& oid,
798 const std::string& start_after,
800 std::map<std::string, bufferlist> *out_vals,
802 int omap_get_vals(const std::string& oid,
803 const std::string& start_after,
804 const std::string& filter_prefix,
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,
811 std::map<std::string, bufferlist> *out_vals,
813 int omap_get_keys(const std::string& oid,
814 const std::string& start_after,
816 std::set<std::string> *out_keys);
817 int omap_get_keys2(const std::string& oid,
818 const std::string& start_after,
820 std::set<std::string> *out_keys,
822 int omap_get_header(const std::string& oid,
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);
835 void snap_set_read(snap_t seq);
836 int selfmanaged_snap_set_write_ctx(snap_t seq, std::vector<snap_t>& snaps);
838 // Create a snapshot with a given name
839 int snap_create(const char *snapname);
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);
845 // Gets a timestamp for a snap
846 int snap_get_stamp(snap_t snapid, time_t *t);
848 // Gets the name of a snap
849 int snap_get_name(snap_t snapid, std::string *s);
851 // Remove a snapshot from this pool
852 int snap_remove(const char *snapname);
854 int snap_list(std::vector<snap_t> *snaps);
856 int snap_rollback(const std::string& oid, const char *snapname);
858 // Deprecated name kept for backward compatibility - same as snap_rollback()
859 int rollback(const std::string& oid, const char *snapname)
860 __attribute__ ((deprecated));
862 int selfmanaged_snap_create(uint64_t *snapid);
863 void aio_selfmanaged_snap_create(uint64_t *snapid, AioCompletion *c);
865 int selfmanaged_snap_remove(uint64_t snapid);
866 void aio_selfmanaged_snap_remove(uint64_t snapid, AioCompletion *c);
868 int selfmanaged_snap_rollback(const std::string& oid, uint64_t snapid);
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);
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);
881 int unlock(const std::string &oid, const std::string &name,
882 const std::string &cookie);
884 int break_lock(const std::string &oid, const std::string &name,
885 const std::string &client, const std::string &cookie);
887 int list_lockers(const std::string &oid, const std::string &name,
890 std::list<librados::locker_t> *lockers);
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;
907 /// Get cursor for pool beginning
908 ObjectCursor object_list_begin();
910 /// Get cursor for pool end
911 ObjectCursor object_list_end();
913 /// Check whether a cursor is at the end of a pool
914 bool object_list_is_end(const ObjectCursor &oc);
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,
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,
929 ObjectCursor *split_start,
930 ObjectCursor *split_finish);
933 * List available hit set objects
935 * @param uint32_t [in] hash position to query
936 * @param c [in] completion
937 * @param pls [out] list of available intervals
939 int hit_set_list(uint32_t hash, AioCompletion *c,
940 std::list< std::pair<time_t, time_t> > *pls);
943 * Retrieve hit set for a given hash, and time
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
950 int hit_set_get(uint32_t hash, AioCompletion *c, time_t stamp,
953 uint64_t get_last_version();
955 int aio_read(const std::string& oid, AioCompletion *c,
956 bufferlist *pbl, size_t len, uint64_t off);
958 * Asynchronously read from an object at a particular snapshot
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.
964 * The return value of the completion will be number of bytes read on
965 * success, negative error code on failure.
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
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);
981 * Asynchronously read existing extents from an object at a
982 * particular snapshot
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.
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.
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
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);
1006 * Asynchronously compare an on-disk object range with a buffer
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
1015 int aio_cmpext(const std::string& oid,
1016 librados::AioCompletion *c,
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,
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);
1028 * Asychronously remove an object
1030 * Queues the remove and returns.
1032 * The return value of the completion will be 0 on success, negative
1033 * error code on failure.
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
1040 int aio_remove(const std::string& oid, AioCompletion *c);
1041 int aio_remove(const std::string& oid, AioCompletion *c, int flags);
1044 * Wait for all currently pending aio writes to be safe.
1046 * @returns 0 on success, negative error code on failure
1051 * Schedule a callback for when all currently pending
1052 * aio writes are safe. This is a non-blocking version of
1055 * @param c what to do when the writes are safe
1056 * @returns 0 on success, negative error code on failure
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);
1067 * Cancel aio operation
1069 * @param c completion handle
1070 * @returns 0 on success, negative error code on failure
1072 int aio_cancel(AioCompletion *c);
1074 int aio_exec(const std::string& oid, AioCompletion *c, const char *cls, const char *method,
1075 bufferlist& inbl, bufferlist *outbl);
1078 * asynchronous version of unlock
1080 int aio_unlock(const std::string &oid, const std::string &name,
1081 const std::string &cookie, AioCompletion *c);
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);
1089 * Schedule an async write operation with explicit snapshot parameters
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.
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
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);
1112 int aio_operate(const std::string& oid, AioCompletion *c,
1113 ObjectReadOperation *op, snap_t snapid, int flags,
1115 __attribute__ ((deprecated));
1117 int aio_operate(const std::string& oid, AioCompletion *c,
1118 ObjectReadOperation *op, int flags,
1120 int aio_operate(const std::string& oid, AioCompletion *c,
1121 ObjectReadOperation *op, int flags,
1122 bufferlist *pbl, const blkin_trace_info *trace_info);
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);
1136 * Send a notify event ot watchers
1138 * Upon completion the pbl bufferlist reply payload will be
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
1150 * le64 gid global id for the client
1151 * le64 cookie cookie for the client
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
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);
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
1177 * check on watch validity
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.
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().
1187 * @param cookie watch handle
1188 * @returns ms since last confirmed valid, or error
1190 int watch_check(uint64_t cookie);
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));
1201 * Set allocation hint for an object
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.
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
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,
1220 // assert version for next sync operations
1221 void set_assert_version(uint64_t ver);
1224 * Pin/unpin an object in cache tier
1226 * @param o the name of the object
1227 * @returns 0 on success, negative error code on failure
1229 int cache_pin(const std::string& o);
1230 int cache_unpin(const std::string& o);
1232 std::string get_pool_name() const;
1234 void locator_set_key(const std::string& key);
1235 void set_namespace(const std::string& nspace);
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));
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);
1250 void set_osdmap_full_try();
1251 void unset_osdmap_full_try();
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);
1269 /* You can only get IoCtx instances from Rados */
1270 IoCtx(IoCtxImpl *io_ctx_impl_);
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
1276 IoCtxImpl *io_ctx_impl;
1279 struct PlacementGroupImpl;
1280 struct CEPH_RADOS_API PlacementGroup {
1282 PlacementGroup(const PlacementGroup&);
1284 bool parse(const char*);
1285 std::unique_ptr<PlacementGroupImpl> impl;
1288 CEPH_RADOS_API std::ostream& operator<<(std::ostream&, const PlacementGroup&);
1290 class CEPH_RADOS_API Rados
1293 static void version(int *major, int *minor, int *extra);
1296 explicit Rados(IoCtx& ioctx);
1299 int init(const char * const id);
1300 int init2(const char * const name, const char * const clustername,
1302 int init_with_context(config_t cct_);
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);
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);
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);
1335 uint64_t get_instance_id();
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);
1346 int ioctx_create(const char *name, IoCtx &pioctx);
1347 int ioctx_create2(int64_t pool_id, IoCtx &pioctx);
1349 // Features useful for test cases
1350 void test_blacklist_self(bool set);
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,
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);
1367 int cluster_stat(cluster_stat_t& result);
1368 int cluster_fsid(std::string *fsid);
1371 * List inconsistent placement groups in the given pool
1373 * @param pool_id the pool id
1374 * @param pgs [out] the inconsistent PGs
1376 int get_inconsistent_pgs(int64_t pool_id,
1377 std::vector<PlacementGroup>* pgs);
1379 * List the inconsistent objects found in a given PG by last scrub
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.
1390 int get_inconsistent_objects(const PlacementGroup& pg,
1391 const object_id_t &start_after,
1392 unsigned max_return,
1394 std::vector<inconsistent_obj_t>* objects,
1395 uint32_t* interval);
1397 * List the inconsistent snapsets found in a given PG by last scrub
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.
1408 int get_inconsistent_snapsets(const PlacementGroup& pg,
1409 const object_id_t &start_after,
1410 unsigned max_return,
1412 std::vector<inconsistent_snapset_t>* snapset,
1413 uint32_t* interval);
1415 /// get/wait for the most recent osdmap
1416 int wait_for_latest_osdmap();
1418 int blacklist_add(const std::string& client_address,
1419 uint32_t expire_seconds);
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
1427 static PoolAsyncCompletion *pool_async_create_completion();
1430 static AioCompletion *aio_create_completion();
1431 static AioCompletion *aio_create_completion(void *cb_arg, callback_t cb_complete,
1432 callback_t cb_safe);
1434 friend std::ostream& operator<<(std::ostream &oss, const Rados& r);
1436 // We don't allow assignment or copying
1437 Rados(const Rados& rhs);
1438 const Rados& operator=(const Rados& rhs);
1439 RadosClient *client;