]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/rados/librados.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / include / rados / librados.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2012 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_LIBRADOS_H
16 #define CEPH_LIBRADOS_H
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #include <netinet/in.h>
23 #if defined(__linux__)
24 #include <linux/types.h>
25 #elif defined(__FreeBSD__)
26 #include <sys/types.h>
27 #endif
28 #include <unistd.h>
29 #include <string.h>
30 #include "rados_types.h"
31
32 #include <sys/time.h>
33
34 #ifndef CEPH_OSD_TMAP_SET
35 /* These are also defined in rados.h and objclass.h. Keep them in sync! */
36 #define CEPH_OSD_TMAP_HDR 'h'
37 #define CEPH_OSD_TMAP_SET 's'
38 #define CEPH_OSD_TMAP_CREATE 'c'
39 #define CEPH_OSD_TMAP_RM 'r'
40 #endif
41
42 #define LIBRADOS_VER_MAJOR 3
43 #define LIBRADOS_VER_MINOR 0
44 #define LIBRADOS_VER_EXTRA 0
45
46 #define LIBRADOS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
47
48 #define LIBRADOS_VERSION_CODE LIBRADOS_VERSION(LIBRADOS_VER_MAJOR, LIBRADOS_VER_MINOR, LIBRADOS_VER_EXTRA)
49
50 #define LIBRADOS_SUPPORTS_WATCH 1
51 #define LIBRADOS_SUPPORTS_SERVICES 1
52 #define LIBRADOS_SUPPORTS_GETADDRS 1
53 #define LIBRADOS_SUPPORTS_APP_METADATA 1
54
55 /* RADOS lock flags
56 * They are also defined in cls_lock_types.h. Keep them in sync!
57 */
58 #define LIBRADOS_LOCK_FLAG_RENEW (1u<<0)
59 #define LIBRADOS_LOCK_FLAG_MAY_RENEW LIBRADOS_LOCK_FLAG_RENEW
60 #define LIBRADOS_LOCK_FLAG_MUST_RENEW (1u<<1)
61
62 /*
63 * Constants for rados_write_op_create().
64 */
65 #define LIBRADOS_CREATE_EXCLUSIVE 1
66 #define LIBRADOS_CREATE_IDEMPOTENT 0
67
68 /*
69 * Flags that can be set on a per-op basis via
70 * rados_read_op_set_flags() and rados_write_op_set_flags().
71 */
72 enum {
73 // fail a create operation if the object already exists
74 LIBRADOS_OP_FLAG_EXCL = 0x1,
75 // allow the transaction to succeed even if the flagged op fails
76 LIBRADOS_OP_FLAG_FAILOK = 0x2,
77 // indicate read/write op random
78 LIBRADOS_OP_FLAG_FADVISE_RANDOM = 0x4,
79 // indicate read/write op sequential
80 LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL = 0x8,
81 // indicate read/write data will be accessed in the near future (by someone)
82 LIBRADOS_OP_FLAG_FADVISE_WILLNEED = 0x10,
83 // indicate read/write data will not accessed in the near future (by anyone)
84 LIBRADOS_OP_FLAG_FADVISE_DONTNEED = 0x20,
85 // indicate read/write data will not accessed again (by *this* client)
86 LIBRADOS_OP_FLAG_FADVISE_NOCACHE = 0x40,
87 // optionally support FUA (force unit access) on write requests
88 LIBRADOS_OP_FLAG_FADVISE_FUA = 0x80,
89 };
90
91 #define CEPH_RADOS_API
92
93 /**
94 * @name xattr comparison operations
95 * Operators for comparing xattrs on objects, and aborting the
96 * rados_read_op or rados_write_op transaction if the comparison
97 * fails.
98 *
99 * @{
100 */
101 enum {
102 LIBRADOS_CMPXATTR_OP_EQ = 1,
103 LIBRADOS_CMPXATTR_OP_NE = 2,
104 LIBRADOS_CMPXATTR_OP_GT = 3,
105 LIBRADOS_CMPXATTR_OP_GTE = 4,
106 LIBRADOS_CMPXATTR_OP_LT = 5,
107 LIBRADOS_CMPXATTR_OP_LTE = 6
108 };
109 /** @} */
110
111 /**
112 * @name Operation Flags
113 * Flags for rados_read_op_operate(), rados_write_op_operate(),
114 * rados_aio_read_op_operate(), and rados_aio_write_op_operate().
115 * See librados.hpp for details.
116 * @{
117 */
118 enum {
119 LIBRADOS_OPERATION_NOFLAG = 0,
120 LIBRADOS_OPERATION_BALANCE_READS = 1,
121 LIBRADOS_OPERATION_LOCALIZE_READS = 2,
122 LIBRADOS_OPERATION_ORDER_READS_WRITES = 4,
123 LIBRADOS_OPERATION_IGNORE_CACHE = 8,
124 LIBRADOS_OPERATION_SKIPRWLOCKS = 16,
125 LIBRADOS_OPERATION_IGNORE_OVERLAY = 32,
126 /* send requests to cluster despite the cluster or pool being marked
127 full; ops will either succeed (e.g., delete) or return EDQUOT or
128 ENOSPC. */
129 LIBRADOS_OPERATION_FULL_TRY = 64,
130 /*
131 * Mainly for delete op
132 */
133 LIBRADOS_OPERATION_FULL_FORCE = 128,
134 LIBRADOS_OPERATION_IGNORE_REDIRECT = 256,
135 LIBRADOS_OPERATION_ORDERSNAP = 512,
136 /* enable/allow >0 return values and payloads on write/update */
137 LIBRADOS_OPERATION_RETURNVEC = 1024,
138 };
139 /** @} */
140
141 /**
142 * @name Alloc hint flags
143 * Flags for rados_write_op_alloc_hint2() and rados_set_alloc_hint2()
144 * indicating future IO patterns.
145 * @{
146 */
147 enum {
148 LIBRADOS_ALLOC_HINT_FLAG_SEQUENTIAL_WRITE = 1,
149 LIBRADOS_ALLOC_HINT_FLAG_RANDOM_WRITE = 2,
150 LIBRADOS_ALLOC_HINT_FLAG_SEQUENTIAL_READ = 4,
151 LIBRADOS_ALLOC_HINT_FLAG_RANDOM_READ = 8,
152 LIBRADOS_ALLOC_HINT_FLAG_APPEND_ONLY = 16,
153 LIBRADOS_ALLOC_HINT_FLAG_IMMUTABLE = 32,
154 LIBRADOS_ALLOC_HINT_FLAG_SHORTLIVED = 64,
155 LIBRADOS_ALLOC_HINT_FLAG_LONGLIVED = 128,
156 LIBRADOS_ALLOC_HINT_FLAG_COMPRESSIBLE = 256,
157 LIBRADOS_ALLOC_HINT_FLAG_INCOMPRESSIBLE = 512,
158 };
159 /** @} */
160
161 typedef enum {
162 LIBRADOS_CHECKSUM_TYPE_XXHASH32 = 0,
163 LIBRADOS_CHECKSUM_TYPE_XXHASH64 = 1,
164 LIBRADOS_CHECKSUM_TYPE_CRC32C = 2
165 } rados_checksum_type_t;
166
167 /*
168 * snap id contants
169 */
170 #define LIBRADOS_SNAP_HEAD ((uint64_t)(-2))
171 #define LIBRADOS_SNAP_DIR ((uint64_t)(-1))
172
173 /**
174 * @typedef rados_t
175 *
176 * A handle for interacting with a RADOS cluster. It encapsulates all
177 * RADOS client configuration, including username, key for
178 * authentication, logging, and debugging. Talking to different clusters
179 * -- or to the same cluster with different users -- requires
180 * different cluster handles.
181 */
182 #ifndef VOIDPTR_RADOS_T
183 #define VOIDPTR_RADOS_T
184 typedef void *rados_t;
185 #endif //VOIDPTR_RADOS_T
186
187 /**
188 * @typedef rados_config_t
189 *
190 * A handle for the ceph configuration context for the rados_t cluster
191 * instance. This can be used to share configuration context/state
192 * (e.g., logging configuration) between librados instance.
193 *
194 * @warning The config context does not have independent reference
195 * counting. As such, a rados_config_t handle retrieved from a given
196 * rados_t is only valid as long as that rados_t.
197 */
198 typedef void *rados_config_t;
199
200 /**
201 * @typedef rados_ioctx_t
202 *
203 * An io context encapsulates a few settings for all I/O operations
204 * done on it:
205 * - pool - set when the io context is created (see rados_ioctx_create())
206 * - snapshot context for writes (see
207 * rados_ioctx_selfmanaged_snap_set_write_ctx())
208 * - snapshot id to read from (see rados_ioctx_snap_set_read())
209 * - object locator for all single-object operations (see
210 * rados_ioctx_locator_set_key())
211 * - namespace for all single-object operations (see
212 * rados_ioctx_set_namespace()). Set to LIBRADOS_ALL_NSPACES
213 * before rados_nobjects_list_open() will list all objects in all
214 * namespaces.
215 *
216 * @warning Changing any of these settings is not thread-safe -
217 * librados users must synchronize any of these changes on their own,
218 * or use separate io contexts for each thread
219 */
220 typedef void *rados_ioctx_t;
221
222 /**
223 * @typedef rados_list_ctx_t
224 *
225 * An iterator for listing the objects in a pool.
226 * Used with rados_nobjects_list_open(),
227 * rados_nobjects_list_next(), rados_nobjects_list_next2(), and
228 * rados_nobjects_list_close().
229 */
230 typedef void *rados_list_ctx_t;
231
232 /**
233 * @typedef rados_object_list_cursor
234 *
235 * The cursor used with rados_enumerate_objects
236 * and accompanying methods.
237 */
238 typedef void * rados_object_list_cursor;
239
240 /**
241 * @struct rados_object_list_item
242 *
243 * The item populated by rados_object_list in
244 * the results array.
245 */
246 typedef struct {
247
248 /// oid length
249 size_t oid_length;
250 /// name of the object
251 char *oid;
252 /// namespace length
253 size_t nspace_length;
254 /// the object namespace
255 char *nspace;
256 /// locator length
257 size_t locator_length;
258 /// object locator
259 char *locator;
260 } rados_object_list_item;
261
262 /**
263 * @typedef rados_snap_t
264 * The id of a snapshot.
265 */
266 typedef uint64_t rados_snap_t;
267
268 /**
269 * @typedef rados_xattrs_iter_t
270 * An iterator for listing extended attrbutes on an object.
271 * Used with rados_getxattrs(), rados_getxattrs_next(), and
272 * rados_getxattrs_end().
273 */
274 typedef void *rados_xattrs_iter_t;
275
276 /**
277 * @typedef rados_omap_iter_t
278 * An iterator for listing omap key/value pairs on an object.
279 * Used with rados_read_op_omap_get_keys(), rados_read_op_omap_get_vals(),
280 * rados_read_op_omap_get_vals_by_keys(), rados_omap_get_next(), and
281 * rados_omap_get_end().
282 */
283 typedef void *rados_omap_iter_t;
284
285 /**
286 * @struct rados_pool_stat_t
287 * Usage information for a pool.
288 */
289 struct rados_pool_stat_t {
290 /// space used in bytes
291 uint64_t num_bytes;
292 /// space used in KB
293 uint64_t num_kb;
294 /// number of objects in the pool
295 uint64_t num_objects;
296 /// number of clones of objects
297 uint64_t num_object_clones;
298 /// num_objects * num_replicas
299 uint64_t num_object_copies;
300 /// number of objects missing on primary
301 uint64_t num_objects_missing_on_primary;
302 /// number of objects found on no OSDs
303 uint64_t num_objects_unfound;
304 /// number of objects replicated fewer times than they should be
305 /// (but found on at least one OSD)
306 uint64_t num_objects_degraded;
307 /// number of objects read
308 uint64_t num_rd;
309 /// objects read in KB
310 uint64_t num_rd_kb;
311 /// number of objects written
312 uint64_t num_wr;
313 /// objects written in KB
314 uint64_t num_wr_kb;
315 /// bytes originally provided by user
316 uint64_t num_user_bytes;
317 /// bytes passed compression
318 uint64_t compressed_bytes_orig;
319 /// bytes resulted after compression
320 uint64_t compressed_bytes;
321 /// bytes allocated at storage
322 uint64_t compressed_bytes_alloc;
323 };
324
325 /**
326 * @struct rados_cluster_stat_t
327 * Cluster-wide usage information
328 */
329 struct rados_cluster_stat_t {
330 /// total device size
331 uint64_t kb;
332 /// total used
333 uint64_t kb_used;
334 /// total available/free
335 uint64_t kb_avail;
336 /// number of objects
337 uint64_t num_objects;
338 };
339
340 /**
341 * @typedef rados_write_op_t
342 *
343 * An object write operation stores a number of operations which can be
344 * executed atomically. For usage, see:
345 * - Creation and deletion: rados_create_write_op() rados_release_write_op()
346 * - Extended attribute manipulation: rados_write_op_cmpxattr()
347 * rados_write_op_cmpxattr(), rados_write_op_setxattr(),
348 * rados_write_op_rmxattr()
349 * - Object map key/value pairs: rados_write_op_omap_set(),
350 * rados_write_op_omap_rm_keys(), rados_write_op_omap_clear(),
351 * rados_write_op_omap_cmp()
352 * - Object properties: rados_write_op_assert_exists(),
353 * rados_write_op_assert_version()
354 * - Creating objects: rados_write_op_create()
355 * - IO on objects: rados_write_op_append(), rados_write_op_write(), rados_write_op_zero
356 * rados_write_op_write_full(), rados_write_op_writesame(), rados_write_op_remove,
357 * rados_write_op_truncate(), rados_write_op_zero(), rados_write_op_cmpext()
358 * - Hints: rados_write_op_set_alloc_hint()
359 * - Performing the operation: rados_write_op_operate(), rados_aio_write_op_operate()
360 */
361 typedef void *rados_write_op_t;
362
363 /**
364 * @typedef rados_read_op_t
365 *
366 * An object read operation stores a number of operations which can be
367 * executed atomically. For usage, see:
368 * - Creation and deletion: rados_create_read_op() rados_release_read_op()
369 * - Extended attribute manipulation: rados_read_op_cmpxattr(),
370 * rados_read_op_getxattr(), rados_read_op_getxattrs()
371 * - Object map key/value pairs: rados_read_op_omap_get_vals(),
372 * rados_read_op_omap_get_keys(), rados_read_op_omap_get_vals_by_keys(),
373 * rados_read_op_omap_cmp()
374 * - Object properties: rados_read_op_stat(), rados_read_op_assert_exists(),
375 * rados_read_op_assert_version()
376 * - IO on objects: rados_read_op_read(), rados_read_op_checksum(),
377 * rados_read_op_cmpext()
378 * - Custom operations: rados_read_op_exec(), rados_read_op_exec_user_buf()
379 * - Request properties: rados_read_op_set_flags()
380 * - Performing the operation: rados_read_op_operate(),
381 * rados_aio_read_op_operate()
382 */
383 typedef void *rados_read_op_t;
384
385 /**
386 * @typedef rados_completion_t
387 * Represents the state of an asynchronous operation - it contains the
388 * return value once the operation completes, and can be used to block
389 * until the operation is complete or safe.
390 */
391 typedef void *rados_completion_t;
392
393 /**
394 * @struct blkin_trace_info
395 * blkin trace information for Zipkin tracing
396 */
397 struct blkin_trace_info;
398
399 /**
400 * Get the version of librados.
401 *
402 * The version number is major.minor.extra. Note that this is
403 * unrelated to the Ceph version number.
404 *
405 * TODO: define version semantics, i.e.:
406 * - incrementing major is for backwards-incompatible changes
407 * - incrementing minor is for backwards-compatible changes
408 * - incrementing extra is for bug fixes
409 *
410 * @param major where to store the major version number
411 * @param minor where to store the minor version number
412 * @param extra where to store the extra version number
413 */
414 CEPH_RADOS_API void rados_version(int *major, int *minor, int *extra);
415
416 /**
417 * @name Setup and Teardown
418 * These are the first and last functions to that should be called
419 * when using librados.
420 *
421 * @{
422 */
423
424 /**
425 * Create a handle for communicating with a RADOS cluster.
426 *
427 * Ceph environment variables are read when this is called, so if
428 * $CEPH_ARGS specifies everything you need to connect, no further
429 * configuration is necessary.
430 *
431 * @param cluster where to store the handle
432 * @param id the user to connect as (i.e. admin, not client.admin)
433 * @returns 0 on success, negative error code on failure
434 */
435 CEPH_RADOS_API int rados_create(rados_t *cluster, const char * const id);
436
437 /**
438 * Extended version of rados_create.
439 *
440 * Like rados_create, but
441 * 1) don't assume 'client\.'+id; allow full specification of name
442 * 2) allow specification of cluster name
443 * 3) flags for future expansion
444 */
445 CEPH_RADOS_API int rados_create2(rados_t *pcluster,
446 const char *const clustername,
447 const char * const name, uint64_t flags);
448
449 /**
450 * Initialize a cluster handle from an existing configuration.
451 *
452 * Share configuration state with another rados_t instance.
453 *
454 * @param cluster where to store the handle
455 * @param cct the existing configuration to use
456 * @returns 0 on success, negative error code on failure
457 */
458 CEPH_RADOS_API int rados_create_with_context(rados_t *cluster,
459 rados_config_t cct);
460
461 /**
462 * Ping the monitor with ID mon_id, storing the resulting reply in
463 * buf (if specified) with a maximum size of len.
464 *
465 * The result buffer is allocated on the heap; the caller is
466 * expected to release that memory with rados_buffer_free(). The
467 * buffer and length pointers can be NULL, in which case they are
468 * not filled in.
469 *
470 * @param cluster cluster handle
471 * @param mon_id [in] ID of the monitor to ping
472 * @param outstr [out] double pointer with the resulting reply
473 * @param outstrlen [out] pointer with the size of the reply in outstr
474 */
475 CEPH_RADOS_API int rados_ping_monitor(rados_t cluster, const char *mon_id,
476 char **outstr, size_t *outstrlen);
477
478 /**
479 * Connect to the cluster.
480 *
481 * @note BUG: Before calling this, calling a function that communicates with the
482 * cluster will crash.
483 *
484 * @pre The cluster handle is configured with at least a monitor
485 * address. If cephx is enabled, a client name and secret must also be
486 * set.
487 *
488 * @post If this succeeds, any function in librados may be used
489 *
490 * @param cluster The cluster to connect to.
491 * @returns 0 on success, negative error code on failure
492 */
493 CEPH_RADOS_API int rados_connect(rados_t cluster);
494
495 /**
496 * Disconnects from the cluster.
497 *
498 * For clean up, this is only necessary after rados_connect() has
499 * succeeded.
500 *
501 * @warning This does not guarantee any asynchronous writes have
502 * completed. To do that, you must call rados_aio_flush() on all open
503 * io contexts.
504 *
505 * @warning We implicitly call rados_watch_flush() on shutdown. If
506 * there are watches being used, this should be done explicitly before
507 * destroying the relevant IoCtx. We do it here as a safety measure.
508 *
509 * @post the cluster handle cannot be used again
510 *
511 * @param cluster the cluster to shutdown
512 */
513 CEPH_RADOS_API void rados_shutdown(rados_t cluster);
514
515 /** @} init */
516
517 /**
518 * @name Configuration
519 * These functions read and update Ceph configuration for a cluster
520 * handle. Any configuration changes must be done before connecting to
521 * the cluster.
522 *
523 * Options that librados users might want to set include:
524 * - mon_host
525 * - auth_supported
526 * - key, keyfile, or keyring when using cephx
527 * - log_file, log_to_stderr, err_to_stderr, and log_to_syslog
528 * - debug_rados, debug_objecter, debug_monc, debug_auth, or debug_ms
529 *
530 * See docs.ceph.com for information about available configuration options`
531 *
532 * @{
533 */
534
535 /**
536 * Configure the cluster handle using a Ceph config file
537 *
538 * If path is NULL, the default locations are searched, and the first
539 * found is used. The locations are:
540 * - $CEPH_CONF (environment variable)
541 * - /etc/ceph/ceph.conf
542 * - ~/.ceph/config
543 * - ceph.conf (in the current working directory)
544 *
545 * @pre rados_connect() has not been called on the cluster handle
546 *
547 * @param cluster cluster handle to configure
548 * @param path path to a Ceph configuration file
549 * @returns 0 on success, negative error code on failure
550 */
551 CEPH_RADOS_API int rados_conf_read_file(rados_t cluster, const char *path);
552
553 /**
554 * Configure the cluster handle with command line arguments
555 *
556 * argv can contain any common Ceph command line option, including any
557 * configuration parameter prefixed by '--' and replacing spaces with
558 * dashes or underscores. For example, the following options are equivalent:
559 * - --mon-host 10.0.0.1:6789
560 * - --mon_host 10.0.0.1:6789
561 * - -m 10.0.0.1:6789
562 *
563 * @pre rados_connect() has not been called on the cluster handle
564 *
565 * @param cluster cluster handle to configure
566 * @param argc number of arguments in argv
567 * @param argv arguments to parse
568 * @returns 0 on success, negative error code on failure
569 */
570 CEPH_RADOS_API int rados_conf_parse_argv(rados_t cluster, int argc,
571 const char **argv);
572
573
574 /**
575 * Configure the cluster handle with command line arguments, returning
576 * any remainders. Same rados_conf_parse_argv, except for extra
577 * remargv argument to hold returns unrecognized arguments.
578 *
579 * @pre rados_connect() has not been called on the cluster handle
580 *
581 * @param cluster cluster handle to configure
582 * @param argc number of arguments in argv
583 * @param argv arguments to parse
584 * @param remargv char* array for returned unrecognized arguments
585 * @returns 0 on success, negative error code on failure
586 */
587 CEPH_RADOS_API int rados_conf_parse_argv_remainder(rados_t cluster, int argc,
588 const char **argv,
589 const char **remargv);
590 /**
591 * Configure the cluster handle based on an environment variable
592 *
593 * The contents of the environment variable are parsed as if they were
594 * Ceph command line options. If var is NULL, the CEPH_ARGS
595 * environment variable is used.
596 *
597 * @pre rados_connect() has not been called on the cluster handle
598 *
599 * @note BUG: this is not threadsafe - it uses a static buffer
600 *
601 * @param cluster cluster handle to configure
602 * @param var name of the environment variable to read
603 * @returns 0 on success, negative error code on failure
604 */
605 CEPH_RADOS_API int rados_conf_parse_env(rados_t cluster, const char *var);
606
607 /**
608 * Set a configuration option
609 *
610 * @pre rados_connect() has not been called on the cluster handle
611 *
612 * @param cluster cluster handle to configure
613 * @param option option to set
614 * @param value value of the option
615 * @returns 0 on success, negative error code on failure
616 * @returns -ENOENT when the option is not a Ceph configuration option
617 */
618 CEPH_RADOS_API int rados_conf_set(rados_t cluster, const char *option,
619 const char *value);
620
621 /**
622 * Get the value of a configuration option
623 *
624 * @param cluster configuration to read
625 * @param option which option to read
626 * @param buf where to write the configuration value
627 * @param len the size of buf in bytes
628 * @returns 0 on success, negative error code on failure
629 * @returns -ENAMETOOLONG if the buffer is too short to contain the
630 * requested value
631 */
632 CEPH_RADOS_API int rados_conf_get(rados_t cluster, const char *option,
633 char *buf, size_t len);
634
635 /** @} config */
636
637 /**
638 * Read usage info about the cluster
639 *
640 * This tells you total space, space used, space available, and number
641 * of objects. These are not updated immediately when data is written,
642 * they are eventually consistent.
643 *
644 * @param cluster cluster to query
645 * @param result where to store the results
646 * @returns 0 on success, negative error code on failure
647 */
648 CEPH_RADOS_API int rados_cluster_stat(rados_t cluster,
649 struct rados_cluster_stat_t *result);
650
651 /**
652 * Get the fsid of the cluster as a hexadecimal string.
653 *
654 * The fsid is a unique id of an entire Ceph cluster.
655 *
656 * @param cluster where to get the fsid
657 * @param buf where to write the fsid
658 * @param len the size of buf in bytes (should be 37)
659 * @returns 0 on success, negative error code on failure
660 * @returns -ERANGE if the buffer is too short to contain the
661 * fsid
662 */
663 CEPH_RADOS_API int rados_cluster_fsid(rados_t cluster, char *buf, size_t len);
664
665 /**
666 * Get/wait for the most recent osdmap
667 *
668 * @param cluster the cluster to shutdown
669 * @returns 0 on success, negative error code on failure
670 */
671 CEPH_RADOS_API int rados_wait_for_latest_osdmap(rados_t cluster);
672
673 /**
674 * @name Pools
675 *
676 * RADOS pools are separate namespaces for objects. Pools may have
677 * different crush rules associated with them, so they could have
678 * differing replication levels or placement strategies. RADOS
679 * permissions are also tied to pools - users can have different read,
680 * write, and execute permissions on a per-pool basis.
681 *
682 * @{
683 */
684
685 /**
686 * List pools
687 *
688 * Gets a list of pool names as NULL-terminated strings. The pool
689 * names will be placed in the supplied buffer one after another.
690 * After the last pool name, there will be two 0 bytes in a row.
691 *
692 * If len is too short to fit all the pool name entries we need, we will fill
693 * as much as we can.
694 *
695 * Buf may be null to determine the buffer size needed to list all pools.
696 *
697 * @param cluster cluster handle
698 * @param buf output buffer
699 * @param len output buffer length
700 * @returns length of the buffer we would need to list all pools
701 */
702 CEPH_RADOS_API int rados_pool_list(rados_t cluster, char *buf, size_t len);
703
704 /**
705 * List inconsistent placement groups of the given pool
706 *
707 * Gets a list of inconsistent placement groups as NULL-terminated strings.
708 * The placement group names will be placed in the supplied buffer one after
709 * another. After the last name, there will be two 0 types in a row.
710 *
711 * If len is too short to fit all the placement group entries we need, we will
712 * fill as much as we can.
713 *
714 * @param cluster cluster handle
715 * @param pool pool ID
716 * @param buf output buffer
717 * @param len output buffer length
718 * @returns length of the buffer we would need to list all pools
719 */
720 CEPH_RADOS_API int rados_inconsistent_pg_list(rados_t cluster, int64_t pool,
721 char *buf, size_t len);
722
723 /**
724 * Get a configuration handle for a rados cluster handle
725 *
726 * This handle is valid only as long as the cluster handle is valid.
727 *
728 * @param cluster cluster handle
729 * @returns config handle for this cluster
730 */
731 CEPH_RADOS_API rados_config_t rados_cct(rados_t cluster);
732
733 /**
734 * Get a global id for current instance
735 *
736 * This id is a unique representation of current connection to the cluster
737 *
738 * @param cluster cluster handle
739 * @returns instance global id
740 */
741 CEPH_RADOS_API uint64_t rados_get_instance_id(rados_t cluster);
742
743 /**
744 * Gets the minimum compatible OSD version
745 *
746 * @param cluster cluster handle
747 * @param require_osd_release [out] minimum compatible OSD version
748 * based upon the current features
749 * @returns 0 on sucess, negative error code on failure
750 */
751 CEPH_RADOS_API int rados_get_min_compatible_osd(rados_t cluster,
752 int8_t* require_osd_release);
753
754 /**
755 * Gets the minimum compatible client version
756 *
757 * @param cluster cluster handle
758 * @param min_compat_client [out] minimum compatible client version
759 * based upon the current features
760 * @param require_min_compat_client [out] required minimum client version
761 * based upon explicit setting
762 * @returns 0 on success, negative error code on failure
763 */
764 CEPH_RADOS_API int rados_get_min_compatible_client(rados_t cluster,
765 int8_t* min_compat_client,
766 int8_t* require_min_compat_client);
767
768 /**
769 * Create an io context
770 *
771 * The io context allows you to perform operations within a particular
772 * pool. For more details see rados_ioctx_t.
773 *
774 * @param cluster which cluster the pool is in
775 * @param pool_name name of the pool
776 * @param ioctx where to store the io context
777 * @returns 0 on success, negative error code on failure
778 */
779 CEPH_RADOS_API int rados_ioctx_create(rados_t cluster, const char *pool_name,
780 rados_ioctx_t *ioctx);
781 CEPH_RADOS_API int rados_ioctx_create2(rados_t cluster, int64_t pool_id,
782 rados_ioctx_t *ioctx);
783
784 /**
785 * The opposite of rados_ioctx_create
786 *
787 * This just tells librados that you no longer need to use the io context.
788 * It may not be freed immediately if there are pending asynchronous
789 * requests on it, but you should not use an io context again after
790 * calling this function on it.
791 *
792 * @warning This does not guarantee any asynchronous
793 * writes have completed. You must call rados_aio_flush()
794 * on the io context before destroying it to do that.
795 *
796 * @warning If this ioctx is used by rados_watch, the caller needs to
797 * be sure that all registered watches are disconnected via
798 * rados_unwatch() and that rados_watch_flush() is called. This
799 * ensures that a racing watch callback does not make use of a
800 * destroyed ioctx.
801 *
802 * @param io the io context to dispose of
803 */
804 CEPH_RADOS_API void rados_ioctx_destroy(rados_ioctx_t io);
805
806 /**
807 * Get configuration handle for a pool handle
808 *
809 * @param io pool handle
810 * @returns rados_config_t for this cluster
811 */
812 CEPH_RADOS_API rados_config_t rados_ioctx_cct(rados_ioctx_t io);
813
814 /**
815 * Get the cluster handle used by this rados_ioctx_t
816 * Note that this is a weak reference, and should not
817 * be destroyed via rados_shutdown().
818 *
819 * @param io the io context
820 * @returns the cluster handle for this io context
821 */
822 CEPH_RADOS_API rados_t rados_ioctx_get_cluster(rados_ioctx_t io);
823
824 /**
825 * Get pool usage statistics
826 *
827 * Fills in a rados_pool_stat_t after querying the cluster.
828 *
829 * @param io determines which pool to query
830 * @param stats where to store the results
831 * @returns 0 on success, negative error code on failure
832 */
833 CEPH_RADOS_API int rados_ioctx_pool_stat(rados_ioctx_t io,
834 struct rados_pool_stat_t *stats);
835
836 /**
837 * Get the id of a pool
838 *
839 * @param cluster which cluster the pool is in
840 * @param pool_name which pool to look up
841 * @returns id of the pool
842 * @returns -ENOENT if the pool is not found
843 */
844 CEPH_RADOS_API int64_t rados_pool_lookup(rados_t cluster,
845 const char *pool_name);
846
847 /**
848 * Get the name of a pool
849 *
850 * @param cluster which cluster the pool is in
851 * @param id the id of the pool
852 * @param buf where to store the pool name
853 * @param maxlen size of buffer where name will be stored
854 * @returns length of string stored, or -ERANGE if buffer too small
855 */
856 CEPH_RADOS_API int rados_pool_reverse_lookup(rados_t cluster, int64_t id,
857 char *buf, size_t maxlen);
858
859 /**
860 * Create a pool with default settings
861 *
862 * The default crush rule is rule 0.
863 *
864 * @param cluster the cluster in which the pool will be created
865 * @param pool_name the name of the new pool
866 * @returns 0 on success, negative error code on failure
867 */
868 CEPH_RADOS_API int rados_pool_create(rados_t cluster, const char *pool_name);
869
870 /**
871 * Create a pool owned by a specific auid.
872 *
873 * DEPRECATED: auid support has been removed, and this call will be removed in a future
874 * release.
875 *
876 * @param cluster the cluster in which the pool will be created
877 * @param pool_name the name of the new pool
878 * @param auid the id of the owner of the new pool
879 * @returns 0 on success, negative error code on failure
880 */
881 CEPH_RADOS_API int rados_pool_create_with_auid(rados_t cluster,
882 const char *pool_name,
883 uint64_t auid)
884 __attribute__((deprecated));
885
886 /**
887 * Create a pool with a specific CRUSH rule
888 *
889 * @param cluster the cluster in which the pool will be created
890 * @param pool_name the name of the new pool
891 * @param crush_rule_num which rule to use for placement in the new pool1
892 * @returns 0 on success, negative error code on failure
893 */
894 CEPH_RADOS_API int rados_pool_create_with_crush_rule(rados_t cluster,
895 const char *pool_name,
896 uint8_t crush_rule_num);
897
898 /**
899 * Create a pool with a specific CRUSH rule and auid
900 *
901 * DEPRECATED: auid support has been removed and this call will be removed
902 * in a future release.
903 *
904 * This is a combination of rados_pool_create_with_crush_rule() and
905 * rados_pool_create_with_auid().
906 *
907 * @param cluster the cluster in which the pool will be created
908 * @param pool_name the name of the new pool
909 * @param crush_rule_num which rule to use for placement in the new pool2
910 * @param auid the id of the owner of the new pool
911 * @returns 0 on success, negative error code on failure
912 */
913 CEPH_RADOS_API int rados_pool_create_with_all(rados_t cluster,
914 const char *pool_name,
915 uint64_t auid,
916 uint8_t crush_rule_num)
917 __attribute__((deprecated));
918
919 /**
920 * Returns the pool that is the base tier for this pool.
921 *
922 * The return value is the ID of the pool that should be used to read from/write to.
923 * If tiering is not set up for the pool, returns \c pool.
924 *
925 * @param cluster the cluster the pool is in
926 * @param pool ID of the pool to query
927 * @param base_tier [out] base tier, or \c pool if tiering is not configured
928 * @returns 0 on success, negative error code on failure
929 */
930 CEPH_RADOS_API int rados_pool_get_base_tier(rados_t cluster, int64_t pool,
931 int64_t* base_tier);
932
933 /**
934 * Delete a pool and all data inside it
935 *
936 * The pool is removed from the cluster immediately,
937 * but the actual data is deleted in the background.
938 *
939 * @param cluster the cluster the pool is in
940 * @param pool_name which pool to delete
941 * @returns 0 on success, negative error code on failure
942 */
943 CEPH_RADOS_API int rados_pool_delete(rados_t cluster, const char *pool_name);
944
945 /**
946 * Attempt to change an io context's associated auid "owner"
947 *
948 * DEPRECATED: auid support has been removed and this call has no effect.
949 *
950 * Requires that you have write permission on both the current and new
951 * auid.
952 *
953 * @param io reference to the pool to change.
954 * @param auid the auid you wish the io to have.
955 * @returns 0 on success, negative error code on failure
956 */
957 CEPH_RADOS_API int rados_ioctx_pool_set_auid(rados_ioctx_t io, uint64_t auid)
958 __attribute__((deprecated));
959
960
961 /**
962 * Get the auid of a pool
963 *
964 * DEPRECATED: auid support has been removed and this call always reports
965 * CEPH_AUTH_UID_DEFAULT (-1).
966
967 * @param io pool to query
968 * @param auid where to store the auid
969 * @returns 0 on success, negative error code on failure
970 */
971 CEPH_RADOS_API int rados_ioctx_pool_get_auid(rados_ioctx_t io, uint64_t *auid)
972 __attribute__((deprecated));
973
974 /* deprecated, use rados_ioctx_pool_requires_alignment2 instead */
975 CEPH_RADOS_API int rados_ioctx_pool_requires_alignment(rados_ioctx_t io)
976 __attribute__((deprecated));
977
978 /**
979 * Test whether the specified pool requires alignment or not.
980 *
981 * @param io pool to query
982 * @param req 1 if alignment is supported, 0 if not.
983 * @returns 0 on success, negative error code on failure
984 */
985 CEPH_RADOS_API int rados_ioctx_pool_requires_alignment2(rados_ioctx_t io,
986 int *req);
987
988 /* deprecated, use rados_ioctx_pool_required_alignment2 instead */
989 CEPH_RADOS_API uint64_t rados_ioctx_pool_required_alignment(rados_ioctx_t io)
990 __attribute__((deprecated));
991
992 /**
993 * Get the alignment flavor of a pool
994 *
995 * @param io pool to query
996 * @param alignment where to store the alignment flavor
997 * @returns 0 on success, negative error code on failure
998 */
999 CEPH_RADOS_API int rados_ioctx_pool_required_alignment2(rados_ioctx_t io,
1000 uint64_t *alignment);
1001
1002 /**
1003 * Get the pool id of the io context
1004 *
1005 * @param io the io context to query
1006 * @returns the id of the pool the io context uses
1007 */
1008 CEPH_RADOS_API int64_t rados_ioctx_get_id(rados_ioctx_t io);
1009
1010 /**
1011 * Get the pool name of the io context
1012 *
1013 * @param io the io context to query
1014 * @param buf pointer to buffer where name will be stored
1015 * @param maxlen size of buffer where name will be stored
1016 * @returns length of string stored, or -ERANGE if buffer too small
1017 */
1018 CEPH_RADOS_API int rados_ioctx_get_pool_name(rados_ioctx_t io, char *buf,
1019 unsigned maxlen);
1020
1021 /** @} pools */
1022
1023 /**
1024 * @name Object Locators
1025 *
1026 * @{
1027 */
1028
1029 /**
1030 * Set the key for mapping objects to pgs within an io context.
1031 *
1032 * The key is used instead of the object name to determine which
1033 * placement groups an object is put in. This affects all subsequent
1034 * operations of the io context - until a different locator key is
1035 * set, all objects in this io context will be placed in the same pg.
1036 *
1037 * @param io the io context to change
1038 * @param key the key to use as the object locator, or NULL to discard
1039 * any previously set key
1040 */
1041 CEPH_RADOS_API void rados_ioctx_locator_set_key(rados_ioctx_t io,
1042 const char *key);
1043
1044 /**
1045 * Set the namespace for objects within an io context
1046 *
1047 * The namespace specification further refines a pool into different
1048 * domains. The mapping of objects to pgs is also based on this
1049 * value.
1050 *
1051 * @param io the io context to change
1052 * @param nspace the name to use as the namespace, or NULL use the
1053 * default namespace
1054 */
1055 CEPH_RADOS_API void rados_ioctx_set_namespace(rados_ioctx_t io,
1056 const char *nspace);
1057
1058 /**
1059 * Get the namespace for objects within the io context
1060 *
1061 * @param io the io context to query
1062 * @param buf pointer to buffer where name will be stored
1063 * @param maxlen size of buffer where name will be stored
1064 * @returns length of string stored, or -ERANGE if buffer too small
1065 */
1066 CEPH_RADOS_API int rados_ioctx_get_namespace(rados_ioctx_t io, char *buf,
1067 unsigned maxlen);
1068
1069 /** @} obj_loc */
1070
1071 /**
1072 * @name Listing Objects
1073 * @{
1074 */
1075 /**
1076 * Start listing objects in a pool
1077 *
1078 * @param io the pool to list from
1079 * @param ctx the handle to store list context in
1080 * @returns 0 on success, negative error code on failure
1081 */
1082 CEPH_RADOS_API int rados_nobjects_list_open(rados_ioctx_t io,
1083 rados_list_ctx_t *ctx);
1084
1085 /**
1086 * Return hash position of iterator, rounded to the current PG
1087 *
1088 * @param ctx iterator marking where you are in the listing
1089 * @returns current hash position, rounded to the current pg
1090 */
1091 CEPH_RADOS_API uint32_t rados_nobjects_list_get_pg_hash_position(rados_list_ctx_t ctx);
1092
1093 /**
1094 * Reposition object iterator to a different hash position
1095 *
1096 * @param ctx iterator marking where you are in the listing
1097 * @param pos hash position to move to
1098 * @returns actual (rounded) position we moved to
1099 */
1100 CEPH_RADOS_API uint32_t rados_nobjects_list_seek(rados_list_ctx_t ctx,
1101 uint32_t pos);
1102
1103 /**
1104 * Reposition object iterator to a different position
1105 *
1106 * @param ctx iterator marking where you are in the listing
1107 * @param cursor position to move to
1108 * @returns rounded position we moved to
1109 */
1110 CEPH_RADOS_API uint32_t rados_nobjects_list_seek_cursor(rados_list_ctx_t ctx,
1111 rados_object_list_cursor cursor);
1112
1113 /**
1114 * Reposition object iterator to a different position
1115 *
1116 * The returned handle must be released with rados_object_list_cursor_free().
1117 *
1118 * @param ctx iterator marking where you are in the listing
1119 * @param cursor where to store cursor
1120 * @returns 0 on success, negative error code on failure
1121 */
1122 CEPH_RADOS_API int rados_nobjects_list_get_cursor(rados_list_ctx_t ctx,
1123 rados_object_list_cursor *cursor);
1124
1125 /**
1126 * Get the next object name and locator in the pool
1127 *
1128 * *entry and *key are valid until next call to rados_nobjects_list_*
1129 *
1130 * @param ctx iterator marking where you are in the listing
1131 * @param entry where to store the name of the entry
1132 * @param key where to store the object locator (set to NULL to ignore)
1133 * @param nspace where to store the object namespace (set to NULL to ignore)
1134 * @returns 0 on success, negative error code on failure
1135 * @returns -ENOENT when there are no more objects to list
1136 */
1137 CEPH_RADOS_API int rados_nobjects_list_next(rados_list_ctx_t ctx,
1138 const char **entry,
1139 const char **key,
1140 const char **nspace);
1141
1142 /**
1143 * Get the next object name, locator and their sizes in the pool
1144 *
1145 * The sizes allow to list objects with \0 (the NUL character)
1146 * in .e.g *entry. Is is unusual see such object names but a bug
1147 * in a client has risen the need to handle them as well.
1148 * *entry and *key are valid until next call to rados_nobjects_list_*
1149 *
1150 * @param ctx iterator marking where you are in the listing
1151 * @param entry where to store the name of the entry
1152 * @param key where to store the object locator (set to NULL to ignore)
1153 * @param nspace where to store the object namespace (set to NULL to ignore)
1154 * @param entry_size where to store the size of name of the entry
1155 * @param key_size where to store the size of object locator (set to NULL to ignore)
1156 * @param nspace_size where to store the size of object namespace (set to NULL to ignore)
1157 * @returns 0 on success, negative error code on failure
1158 * @returns -ENOENT when there are no more objects to list
1159 */
1160 CEPH_RADOS_API int rados_nobjects_list_next2(rados_list_ctx_t ctx,
1161 const char **entry,
1162 const char **key,
1163 const char **nspace,
1164 size_t *entry_size,
1165 size_t *key_size,
1166 size_t *nspace_size);
1167
1168 /**
1169 * Close the object listing handle.
1170 *
1171 * This should be called when the handle is no longer needed.
1172 * The handle should not be used after it has been closed.
1173 *
1174 * @param ctx the handle to close
1175 */
1176 CEPH_RADOS_API void rados_nobjects_list_close(rados_list_ctx_t ctx);
1177
1178 /**
1179 * Get cursor handle pointing to the *beginning* of a pool.
1180 *
1181 * This is an opaque handle pointing to the start of a pool. It must
1182 * be released with rados_object_list_cursor_free().
1183 *
1184 * @param io ioctx for the pool
1185 * @returns handle for the pool, NULL on error (pool does not exist)
1186 */
1187 CEPH_RADOS_API rados_object_list_cursor rados_object_list_begin(
1188 rados_ioctx_t io);
1189
1190 /**
1191 * Get cursor handle pointing to the *end* of a pool.
1192 *
1193 * This is an opaque handle pointing to the start of a pool. It must
1194 * be released with rados_object_list_cursor_free().
1195 *
1196 * @param io ioctx for the pool
1197 * @returns handle for the pool, NULL on error (pool does not exist)
1198 */
1199 CEPH_RADOS_API rados_object_list_cursor rados_object_list_end(rados_ioctx_t io);
1200
1201 /**
1202 * Check if a cursor has reached the end of a pool
1203 *
1204 * @param io ioctx
1205 * @param cur cursor
1206 * @returns 1 if the cursor has reached the end of the pool, 0 otherwise
1207 */
1208 CEPH_RADOS_API int rados_object_list_is_end(rados_ioctx_t io,
1209 rados_object_list_cursor cur);
1210
1211 /**
1212 * Release a cursor
1213 *
1214 * Release a cursor. The handle may not be used after this point.
1215 *
1216 * @param io ioctx
1217 * @param cur cursor
1218 */
1219 CEPH_RADOS_API void rados_object_list_cursor_free(rados_ioctx_t io,
1220 rados_object_list_cursor cur);
1221
1222 /**
1223 * Compare two cursor positions
1224 *
1225 * Compare two cursors, and indicate whether the first cursor precedes,
1226 * matches, or follows the second.
1227 *
1228 * @param io ioctx
1229 * @param lhs first cursor
1230 * @param rhs second cursor
1231 * @returns -1, 0, or 1 for lhs < rhs, lhs == rhs, or lhs > rhs
1232 */
1233 CEPH_RADOS_API int rados_object_list_cursor_cmp(rados_ioctx_t io,
1234 rados_object_list_cursor lhs, rados_object_list_cursor rhs);
1235
1236 /**
1237 * @return the number of items set in the results array
1238 */
1239 CEPH_RADOS_API int rados_object_list(rados_ioctx_t io,
1240 const rados_object_list_cursor start,
1241 const rados_object_list_cursor finish,
1242 const size_t result_size,
1243 const char *filter_buf,
1244 const size_t filter_buf_len,
1245 rados_object_list_item *results,
1246 rados_object_list_cursor *next);
1247
1248 CEPH_RADOS_API void rados_object_list_free(
1249 const size_t result_size,
1250 rados_object_list_item *results);
1251
1252 /**
1253 * Obtain cursors delineating a subset of a range. Use this
1254 * when you want to split up the work of iterating over the
1255 * global namespace. Expected use case is when you are iterating
1256 * in parallel, with `m` workers, and each worker taking an id `n`.
1257 *
1258 * @param io ioctx
1259 * @param start start of the range to be sliced up (inclusive)
1260 * @param finish end of the range to be sliced up (exclusive)
1261 * @param n which of the m chunks you would like to get cursors for
1262 * @param m how many chunks to divide start-finish into
1263 * @param split_start cursor populated with start of the subrange (inclusive)
1264 * @param split_finish cursor populated with end of the subrange (exclusive)
1265 */
1266 CEPH_RADOS_API void rados_object_list_slice(rados_ioctx_t io,
1267 const rados_object_list_cursor start,
1268 const rados_object_list_cursor finish,
1269 const size_t n,
1270 const size_t m,
1271 rados_object_list_cursor *split_start,
1272 rados_object_list_cursor *split_finish);
1273
1274
1275 /** @} Listing Objects */
1276
1277 /**
1278 * @name Snapshots
1279 *
1280 * RADOS snapshots are based upon sequence numbers that form a
1281 * snapshot context. They are pool-specific. The snapshot context
1282 * consists of the current snapshot sequence number for a pool, and an
1283 * array of sequence numbers at which snapshots were taken, in
1284 * descending order. Whenever a snapshot is created or deleted, the
1285 * snapshot sequence number for the pool is increased. To add a new
1286 * snapshot, the new snapshot sequence number must be increased and
1287 * added to the snapshot context.
1288 *
1289 * There are two ways to manage these snapshot contexts:
1290 * -# within the RADOS cluster
1291 * These are called pool snapshots, and store the snapshot context
1292 * in the OSDMap. These represent a snapshot of all the objects in
1293 * a pool.
1294 * -# within the RADOS clients
1295 * These are called self-managed snapshots, and push the
1296 * responsibility for keeping track of the snapshot context to the
1297 * clients. For every write, the client must send the snapshot
1298 * context. In librados, this is accomplished with
1299 * rados_selfmanaged_snap_set_write_ctx(). These are more
1300 * difficult to manage, but are restricted to specific objects
1301 * instead of applying to an entire pool.
1302 *
1303 * @{
1304 */
1305
1306 /**
1307 * Create a pool-wide snapshot
1308 *
1309 * @param io the pool to snapshot
1310 * @param snapname the name of the snapshot
1311 * @returns 0 on success, negative error code on failure
1312 */
1313 CEPH_RADOS_API int rados_ioctx_snap_create(rados_ioctx_t io,
1314 const char *snapname);
1315
1316 /**
1317 * Delete a pool snapshot
1318 *
1319 * @param io the pool to delete the snapshot from
1320 * @param snapname which snapshot to delete
1321 * @returns 0 on success, negative error code on failure
1322 */
1323 CEPH_RADOS_API int rados_ioctx_snap_remove(rados_ioctx_t io,
1324 const char *snapname);
1325
1326 /**
1327 * Rollback an object to a pool snapshot
1328 *
1329 * The contents of the object will be the same as
1330 * when the snapshot was taken.
1331 *
1332 * @param io the pool in which the object is stored
1333 * @param oid the name of the object to rollback
1334 * @param snapname which snapshot to rollback to
1335 * @returns 0 on success, negative error code on failure
1336 */
1337 CEPH_RADOS_API int rados_ioctx_snap_rollback(rados_ioctx_t io, const char *oid,
1338 const char *snapname);
1339
1340 /**
1341 * @warning Deprecated: Use rados_ioctx_snap_rollback() instead
1342 */
1343 CEPH_RADOS_API int rados_rollback(rados_ioctx_t io, const char *oid,
1344 const char *snapname)
1345 __attribute__((deprecated));
1346
1347 /**
1348 * Set the snapshot from which reads are performed.
1349 *
1350 * Subsequent reads will return data as it was at the time of that
1351 * snapshot.
1352 *
1353 * @param io the io context to change
1354 * @param snap the id of the snapshot to set, or LIBRADOS_SNAP_HEAD for no
1355 * snapshot (i.e. normal operation)
1356 */
1357 CEPH_RADOS_API void rados_ioctx_snap_set_read(rados_ioctx_t io,
1358 rados_snap_t snap);
1359
1360 /**
1361 * Allocate an ID for a self-managed snapshot
1362 *
1363 * Get a unique ID to put in the snaphot context to create a
1364 * snapshot. A clone of an object is not created until a write with
1365 * the new snapshot context is completed.
1366 *
1367 * @param io the pool in which the snapshot will exist
1368 * @param snapid where to store the newly allocated snapshot ID
1369 * @returns 0 on success, negative error code on failure
1370 */
1371 CEPH_RADOS_API int rados_ioctx_selfmanaged_snap_create(rados_ioctx_t io,
1372 rados_snap_t *snapid);
1373 CEPH_RADOS_API void
1374 rados_aio_ioctx_selfmanaged_snap_create(rados_ioctx_t io,
1375 rados_snap_t *snapid,
1376 rados_completion_t completion);
1377
1378 /**
1379 * Remove a self-managed snapshot
1380 *
1381 * This increases the snapshot sequence number, which will cause
1382 * snapshots to be removed lazily.
1383 *
1384 * @param io the pool in which the snapshot will exist
1385 * @param snapid where to store the newly allocated snapshot ID
1386 * @returns 0 on success, negative error code on failure
1387 */
1388 CEPH_RADOS_API int rados_ioctx_selfmanaged_snap_remove(rados_ioctx_t io,
1389 rados_snap_t snapid);
1390 CEPH_RADOS_API void
1391 rados_aio_ioctx_selfmanaged_snap_remove(rados_ioctx_t io,
1392 rados_snap_t snapid,
1393 rados_completion_t completion);
1394
1395 /**
1396 * Rollback an object to a self-managed snapshot
1397 *
1398 * The contents of the object will be the same as
1399 * when the snapshot was taken.
1400 *
1401 * @param io the pool in which the object is stored
1402 * @param oid the name of the object to rollback
1403 * @param snapid which snapshot to rollback to
1404 * @returns 0 on success, negative error code on failure
1405 */
1406 CEPH_RADOS_API int rados_ioctx_selfmanaged_snap_rollback(rados_ioctx_t io,
1407 const char *oid,
1408 rados_snap_t snapid);
1409
1410 /**
1411 * Set the snapshot context for use when writing to objects
1412 *
1413 * This is stored in the io context, and applies to all future writes.
1414 *
1415 * @param io the io context to change
1416 * @param seq the newest snapshot sequence number for the pool
1417 * @param snaps array of snapshots in sorted by descending id
1418 * @param num_snaps how many snaphosts are in the snaps array
1419 * @returns 0 on success, negative error code on failure
1420 * @returns -EINVAL if snaps are not in descending order
1421 */
1422 CEPH_RADOS_API int rados_ioctx_selfmanaged_snap_set_write_ctx(rados_ioctx_t io,
1423 rados_snap_t seq,
1424 rados_snap_t *snaps,
1425 int num_snaps);
1426
1427 /**
1428 * List all the ids of pool snapshots
1429 *
1430 * If the output array does not have enough space to fit all the
1431 * snapshots, -ERANGE is returned and the caller should retry with a
1432 * larger array.
1433 *
1434 * @param io the pool to read from
1435 * @param snaps where to store the results
1436 * @param maxlen the number of rados_snap_t that fit in the snaps array
1437 * @returns number of snapshots on success, negative error code on failure
1438 * @returns -ERANGE is returned if the snaps array is too short
1439 */
1440 CEPH_RADOS_API int rados_ioctx_snap_list(rados_ioctx_t io, rados_snap_t *snaps,
1441 int maxlen);
1442
1443 /**
1444 * Get the id of a pool snapshot
1445 *
1446 * @param io the pool to read from
1447 * @param name the snapshot to find
1448 * @param id where to store the result
1449 * @returns 0 on success, negative error code on failure
1450 */
1451 CEPH_RADOS_API int rados_ioctx_snap_lookup(rados_ioctx_t io, const char *name,
1452 rados_snap_t *id);
1453
1454 /**
1455 * Get the name of a pool snapshot
1456 *
1457 * @param io the pool to read from
1458 * @param id the snapshot to find
1459 * @param name where to store the result
1460 * @param maxlen the size of the name array
1461 * @returns 0 on success, negative error code on failure
1462 * @returns -ERANGE if the name array is too small
1463 */
1464 CEPH_RADOS_API int rados_ioctx_snap_get_name(rados_ioctx_t io, rados_snap_t id,
1465 char *name, int maxlen);
1466
1467 /**
1468 * Find when a pool snapshot occurred
1469 *
1470 * @param io the pool the snapshot was taken in
1471 * @param id the snapshot to lookup
1472 * @param t where to store the result
1473 * @returns 0 on success, negative error code on failure
1474 */
1475 CEPH_RADOS_API int rados_ioctx_snap_get_stamp(rados_ioctx_t io, rados_snap_t id,
1476 time_t *t);
1477
1478 /** @} Snapshots */
1479
1480 /**
1481 * @name Synchronous I/O
1482 * Writes are replicated to a number of OSDs based on the
1483 * configuration of the pool they are in. These write functions block
1484 * until data is in memory on all replicas of the object they're
1485 * writing to - they are equivalent to doing the corresponding
1486 * asynchronous write, and the calling
1487 * rados_ioctx_wait_for_complete(). For greater data safety, use the
1488 * asynchronous functions and rados_aio_wait_for_safe().
1489 *
1490 * @{
1491 */
1492
1493 /**
1494 * Return the version of the last object read or written to.
1495 *
1496 * This exposes the internal version number of the last object read or
1497 * written via this io context
1498 *
1499 * @param io the io context to check
1500 * @returns last read or written object version
1501 */
1502 CEPH_RADOS_API uint64_t rados_get_last_version(rados_ioctx_t io);
1503
1504 /**
1505 * Write *len* bytes from *buf* into the *oid* object, starting at
1506 * offset *off*. The value of *len* must be <= UINT_MAX/2.
1507 *
1508 * @note This will never return a positive value not equal to len.
1509 * @param io the io context in which the write will occur
1510 * @param oid name of the object
1511 * @param buf data to write
1512 * @param len length of the data, in bytes
1513 * @param off byte offset in the object to begin writing at
1514 * @returns 0 on success, negative error code on failure
1515 */
1516 CEPH_RADOS_API int rados_write(rados_ioctx_t io, const char *oid,
1517 const char *buf, size_t len, uint64_t off);
1518
1519 /**
1520 * Write *len* bytes from *buf* into the *oid* object. The value of
1521 * *len* must be <= UINT_MAX/2.
1522 *
1523 * The object is filled with the provided data. If the object exists,
1524 * it is atomically truncated and then written.
1525 *
1526 * @param io the io context in which the write will occur
1527 * @param oid name of the object
1528 * @param buf data to write
1529 * @param len length of the data, in bytes
1530 * @returns 0 on success, negative error code on failure
1531 */
1532 CEPH_RADOS_API int rados_write_full(rados_ioctx_t io, const char *oid,
1533 const char *buf, size_t len);
1534
1535 /**
1536 * Write the same *data_len* bytes from *buf* multiple times into the
1537 * *oid* object. *write_len* bytes are written in total, which must be
1538 * a multiple of *data_len*. The value of *write_len* and *data_len*
1539 * must be <= UINT_MAX/2.
1540 *
1541 * @param io the io context in which the write will occur
1542 * @param oid name of the object
1543 * @param buf data to write
1544 * @param data_len length of the data, in bytes
1545 * @param write_len the total number of bytes to write
1546 * @param off byte offset in the object to begin writing at
1547 * @returns 0 on success, negative error code on failure
1548 */
1549 CEPH_RADOS_API int rados_writesame(rados_ioctx_t io, const char *oid,
1550 const char *buf, size_t data_len,
1551 size_t write_len, uint64_t off);
1552
1553 /**
1554 * Append *len* bytes from *buf* into the *oid* object. The value of
1555 * *len* must be <= UINT_MAX/2.
1556 *
1557 * @param io the context to operate in
1558 * @param oid the name of the object
1559 * @param buf the data to append
1560 * @param len length of buf (in bytes)
1561 * @returns 0 on success, negative error code on failure
1562 */
1563 CEPH_RADOS_API int rados_append(rados_ioctx_t io, const char *oid,
1564 const char *buf, size_t len);
1565
1566 /**
1567 * Read data from an object
1568 *
1569 * The io context determines the snapshot to read from, if any was set
1570 * by rados_ioctx_snap_set_read().
1571 *
1572 * @param io the context in which to perform the read
1573 * @param oid the name of the object to read from
1574 * @param buf where to store the results
1575 * @param len the number of bytes to read
1576 * @param off the offset to start reading from in the object
1577 * @returns number of bytes read on success, negative error code on
1578 * failure
1579 */
1580 CEPH_RADOS_API int rados_read(rados_ioctx_t io, const char *oid, char *buf,
1581 size_t len, uint64_t off);
1582
1583 /**
1584 * Compute checksum from object data
1585 *
1586 * The io context determines the snapshot to checksum, if any was set
1587 * by rados_ioctx_snap_set_read(). The length of the init_value and
1588 * resulting checksum are dependent upon the checksum type:
1589 *
1590 * XXHASH64: le64
1591 * XXHASH32: le32
1592 * CRC32C: le32
1593 *
1594 * The checksum result is encoded the following manner:
1595 *
1596 * le32 num_checksum_chunks
1597 * {
1598 * leXX checksum for chunk (where XX = appropriate size for the checksum type)
1599 * } * num_checksum_chunks
1600 *
1601 * @param io the context in which to perform the checksum
1602 * @param oid the name of the object to checksum
1603 * @param type the checksum algorithm to utilize
1604 * @param init_value the init value for the algorithm
1605 * @param init_value_len the length of the init value
1606 * @param len the number of bytes to checksum
1607 * @param off the offset to start checksumming in the object
1608 * @param chunk_size optional length-aligned chunk size for checksums
1609 * @param pchecksum where to store the checksum result
1610 * @param checksum_len the number of bytes available for the result
1611 * @return negative error code on failure
1612 */
1613 CEPH_RADOS_API int rados_checksum(rados_ioctx_t io, const char *oid,
1614 rados_checksum_type_t type,
1615 const char *init_value, size_t init_value_len,
1616 size_t len, uint64_t off, size_t chunk_size,
1617 char *pchecksum, size_t checksum_len);
1618
1619 /**
1620 * Delete an object
1621 *
1622 * @note This does not delete any snapshots of the object.
1623 *
1624 * @param io the pool to delete the object from
1625 * @param oid the name of the object to delete
1626 * @returns 0 on success, negative error code on failure
1627 */
1628 CEPH_RADOS_API int rados_remove(rados_ioctx_t io, const char *oid);
1629
1630 /**
1631 * Resize an object
1632 *
1633 * If this enlarges the object, the new area is logically filled with
1634 * zeroes. If this shrinks the object, the excess data is removed.
1635 *
1636 * @param io the context in which to truncate
1637 * @param oid the name of the object
1638 * @param size the new size of the object in bytes
1639 * @returns 0 on success, negative error code on failure
1640 */
1641 CEPH_RADOS_API int rados_trunc(rados_ioctx_t io, const char *oid,
1642 uint64_t size);
1643
1644 /**
1645 * Compare an on-disk object range with a buffer
1646 *
1647 * @param io the context in which to perform the comparison
1648 * @param o name of the object
1649 * @param cmp_buf buffer containing bytes to be compared with object contents
1650 * @param cmp_len length to compare and size of @c cmp_buf in bytes
1651 * @param off object byte offset at which to start the comparison
1652 * @returns 0 on success, negative error code on failure,
1653 * (-MAX_ERRNO - mismatch_off) on mismatch
1654 */
1655 CEPH_RADOS_API int rados_cmpext(rados_ioctx_t io, const char *o,
1656 const char *cmp_buf, size_t cmp_len,
1657 uint64_t off);
1658
1659 /**
1660 * @name Xattrs
1661 * Extended attributes are stored as extended attributes on the files
1662 * representing an object on the OSDs. Thus, they have the same
1663 * limitations as the underlying filesystem. On ext4, this means that
1664 * the total data stored in xattrs cannot exceed 4KB.
1665 *
1666 * @{
1667 */
1668
1669 /**
1670 * Get the value of an extended attribute on an object.
1671 *
1672 * @param io the context in which the attribute is read
1673 * @param o name of the object
1674 * @param name which extended attribute to read
1675 * @param buf where to store the result
1676 * @param len size of buf in bytes
1677 * @returns length of xattr value on success, negative error code on failure
1678 */
1679 CEPH_RADOS_API int rados_getxattr(rados_ioctx_t io, const char *o,
1680 const char *name, char *buf, size_t len);
1681
1682 /**
1683 * Set an extended attribute on an object.
1684 *
1685 * @param io the context in which xattr is set
1686 * @param o name of the object
1687 * @param name which extended attribute to set
1688 * @param buf what to store in the xattr
1689 * @param len the number of bytes in buf
1690 * @returns 0 on success, negative error code on failure
1691 */
1692 CEPH_RADOS_API int rados_setxattr(rados_ioctx_t io, const char *o,
1693 const char *name, const char *buf,
1694 size_t len);
1695
1696 /**
1697 * Delete an extended attribute from an object.
1698 *
1699 * @param io the context in which to delete the xattr
1700 * @param o the name of the object
1701 * @param name which xattr to delete
1702 * @returns 0 on success, negative error code on failure
1703 */
1704 CEPH_RADOS_API int rados_rmxattr(rados_ioctx_t io, const char *o,
1705 const char *name);
1706
1707 /**
1708 * Start iterating over xattrs on an object.
1709 *
1710 * @post iter is a valid iterator
1711 *
1712 * @param io the context in which to list xattrs
1713 * @param oid name of the object
1714 * @param iter where to store the iterator
1715 * @returns 0 on success, negative error code on failure
1716 */
1717 CEPH_RADOS_API int rados_getxattrs(rados_ioctx_t io, const char *oid,
1718 rados_xattrs_iter_t *iter);
1719
1720 /**
1721 * Get the next xattr on the object
1722 *
1723 * @pre iter is a valid iterator
1724 *
1725 * @post name is the NULL-terminated name of the next xattr, and val
1726 * contains the value of the xattr, which is of length len. If the end
1727 * of the list has been reached, name and val are NULL, and len is 0.
1728 *
1729 * @param iter iterator to advance
1730 * @param name where to store the name of the next xattr
1731 * @param val where to store the value of the next xattr
1732 * @param len the number of bytes in val
1733 * @returns 0 on success, negative error code on failure
1734 */
1735 CEPH_RADOS_API int rados_getxattrs_next(rados_xattrs_iter_t iter,
1736 const char **name, const char **val,
1737 size_t *len);
1738
1739 /**
1740 * Close the xattr iterator.
1741 *
1742 * iter should not be used after this is called.
1743 *
1744 * @param iter the iterator to close
1745 */
1746 CEPH_RADOS_API void rados_getxattrs_end(rados_xattrs_iter_t iter);
1747
1748 /** @} Xattrs */
1749
1750 /**
1751 * Get the next omap key/value pair on the object
1752 *
1753 * @pre iter is a valid iterator
1754 *
1755 * @post key and val are the next key/value pair. key is
1756 * null-terminated, and val has length len. If the end of the list has
1757 * been reached, key and val are NULL, and len is 0. key and val will
1758 * not be accessible after rados_omap_get_end() is called on iter, so
1759 * if they are needed after that they should be copied.
1760 *
1761 * @param iter iterator to advance
1762 * @param key where to store the key of the next omap entry
1763 * @param val where to store the value of the next omap entry
1764 * @param len where to store the number of bytes in val
1765 * @returns 0 on success, negative error code on failure
1766 */
1767 CEPH_RADOS_API int rados_omap_get_next(rados_omap_iter_t iter,
1768 char **key,
1769 char **val,
1770 size_t *len);
1771
1772 /**
1773 * Get the next omap key/value pair on the object. Note that it's
1774 * perfectly safe to mix calls to rados_omap_get_next and
1775 * rados_omap_get_next2.
1776 *
1777 * @pre iter is a valid iterator
1778 *
1779 * @post key and val are the next key/value pair. key has length
1780 * keylen and val has length vallen. If the end of the list has
1781 * been reached, key and val are NULL, and keylen and vallen is 0.
1782 * key and val will not be accessible after rados_omap_get_end()
1783 * is called on iter, so if they are needed after that they
1784 * should be copied.
1785 *
1786 * @param iter iterator to advance
1787 * @param key where to store the key of the next omap entry
1788 * @param val where to store the value of the next omap entry
1789 * @param key_len where to store the number of bytes in key
1790 * @param val_len where to store the number of bytes in val
1791 * @returns 0 on success, negative error code on failure
1792 */
1793 CEPH_RADOS_API int rados_omap_get_next2(rados_omap_iter_t iter,
1794 char **key,
1795 char **val,
1796 size_t *key_len,
1797 size_t *val_len);
1798
1799 /**
1800 * Return number of elements in the iterator
1801 *
1802 * @param iter the iterator of which to return the size
1803 */
1804 CEPH_RADOS_API unsigned int rados_omap_iter_size(rados_omap_iter_t iter);
1805
1806 /**
1807 * Close the omap iterator.
1808 *
1809 * iter should not be used after this is called.
1810 *
1811 * @param iter the iterator to close
1812 */
1813 CEPH_RADOS_API void rados_omap_get_end(rados_omap_iter_t iter);
1814
1815 /**
1816 * Get object stats (size/mtime)
1817 *
1818 * TODO: when are these set, and by whom? can they be out of date?
1819 *
1820 * @param io ioctx
1821 * @param o object name
1822 * @param psize where to store object size
1823 * @param pmtime where to store modification time
1824 * @returns 0 on success, negative error code on failure
1825 */
1826 CEPH_RADOS_API int rados_stat(rados_ioctx_t io, const char *o, uint64_t *psize,
1827 time_t *pmtime);
1828 /**
1829 * Execute an OSD class method on an object
1830 *
1831 * The OSD has a plugin mechanism for performing complicated
1832 * operations on an object atomically. These plugins are called
1833 * classes. This function allows librados users to call the custom
1834 * methods. The input and output formats are defined by the class.
1835 * Classes in ceph.git can be found in src/cls subdirectories
1836 *
1837 * @param io the context in which to call the method
1838 * @param oid the object to call the method on
1839 * @param cls the name of the class
1840 * @param method the name of the method
1841 * @param in_buf where to find input
1842 * @param in_len length of in_buf in bytes
1843 * @param buf where to store output
1844 * @param out_len length of buf in bytes
1845 * @returns the length of the output, or
1846 * -ERANGE if out_buf does not have enough space to store it (For methods that return data). For
1847 * methods that don't return data, the return value is
1848 * method-specific.
1849 */
1850 CEPH_RADOS_API int rados_exec(rados_ioctx_t io, const char *oid,
1851 const char *cls, const char *method,
1852 const char *in_buf, size_t in_len, char *buf,
1853 size_t out_len);
1854
1855
1856 /** @} Synchronous I/O */
1857
1858 /**
1859 * @name Asynchronous I/O
1860 * Read and write to objects without blocking.
1861 *
1862 * @{
1863 */
1864
1865 /**
1866 * @typedef rados_callback_t
1867 * Callbacks for asynchrous operations take two parameters:
1868 * - cb the completion that has finished
1869 * - arg application defined data made available to the callback function
1870 */
1871 typedef void (*rados_callback_t)(rados_completion_t cb, void *arg);
1872
1873 /**
1874 * Constructs a completion to use with asynchronous operations
1875 *
1876 * The complete and safe callbacks correspond to operations being
1877 * acked and committed, respectively. The callbacks are called in
1878 * order of receipt, so the safe callback may be triggered before the
1879 * complete callback, and vice versa. This is affected by journalling
1880 * on the OSDs.
1881 *
1882 * TODO: more complete documentation of this elsewhere (in the RADOS docs?)
1883 *
1884 * @note Read operations only get a complete callback.
1885 * @note BUG: this should check for ENOMEM instead of throwing an exception
1886 *
1887 * @param cb_arg application-defined data passed to the callback functions
1888 * @param cb_complete the function to be called when the operation is
1889 * in memory on all replicas
1890 * @param cb_safe the function to be called when the operation is on
1891 * stable storage on all replicas
1892 * @param pc where to store the completion
1893 * @returns 0
1894 */
1895 CEPH_RADOS_API int rados_aio_create_completion(void *cb_arg,
1896 rados_callback_t cb_complete,
1897 rados_callback_t cb_safe,
1898 rados_completion_t *pc);
1899
1900 /**
1901 * Constructs a completion to use with asynchronous operations
1902 *
1903 * The complete callback corresponds to operation being acked.
1904 *
1905 * @note BUG: this should check for ENOMEM instead of throwing an exception
1906 *
1907 * @param cb_arg application-defined data passed to the callback functions
1908 * @param cb_complete the function to be called when the operation is committed
1909 * on all replicas
1910 * @param pc where to store the completion
1911 * @returns 0
1912 */
1913 CEPH_RADOS_API int rados_aio_create_completion2(void *cb_arg,
1914 rados_callback_t cb_complete,
1915 rados_completion_t *pc);
1916
1917 /**
1918 * Block until an operation completes
1919 *
1920 * This means it is in memory on all replicas.
1921 *
1922 * @note BUG: this should be void
1923 *
1924 * @param c operation to wait for
1925 * @returns 0
1926 */
1927 CEPH_RADOS_API int rados_aio_wait_for_complete(rados_completion_t c);
1928
1929 /**
1930 * Block until an operation is safe
1931 *
1932 * This means it is on stable storage on all replicas.
1933 *
1934 * @note BUG: this should be void
1935 *
1936 * @param c operation to wait for
1937 * @returns 0
1938 */
1939 CEPH_RADOS_API int rados_aio_wait_for_safe(rados_completion_t c)
1940 __attribute__((deprecated));
1941
1942 /**
1943 * Has an asynchronous operation completed?
1944 *
1945 * @warning This does not imply that the complete callback has
1946 * finished
1947 *
1948 * @param c async operation to inspect
1949 * @returns whether c is complete
1950 */
1951 CEPH_RADOS_API int rados_aio_is_complete(rados_completion_t c);
1952
1953 /**
1954 * Is an asynchronous operation safe?
1955 *
1956 * @warning This does not imply that the safe callback has
1957 * finished
1958 *
1959 * @param c async operation to inspect
1960 * @returns whether c is safe
1961 */
1962 CEPH_RADOS_API int rados_aio_is_safe(rados_completion_t c);
1963
1964 /**
1965 * Block until an operation completes and callback completes
1966 *
1967 * This means it is in memory on all replicas and can be read.
1968 *
1969 * @note BUG: this should be void
1970 *
1971 * @param c operation to wait for
1972 * @returns 0
1973 */
1974 CEPH_RADOS_API int rados_aio_wait_for_complete_and_cb(rados_completion_t c);
1975
1976 /**
1977 * Block until an operation is safe and callback has completed
1978 *
1979 * This means it is on stable storage on all replicas.
1980 *
1981 * @note BUG: this should be void
1982 *
1983 * @param c operation to wait for
1984 * @returns 0
1985 */
1986 CEPH_RADOS_API int rados_aio_wait_for_safe_and_cb(rados_completion_t c)
1987 __attribute__((deprecated));
1988
1989 /**
1990 * Has an asynchronous operation and callback completed
1991 *
1992 * @param c async operation to inspect
1993 * @returns whether c is complete
1994 */
1995 CEPH_RADOS_API int rados_aio_is_complete_and_cb(rados_completion_t c);
1996
1997 /**
1998 * Is an asynchronous operation safe and has the callback completed
1999 *
2000 * @param c async operation to inspect
2001 * @returns whether c is safe
2002 */
2003 CEPH_RADOS_API int rados_aio_is_safe_and_cb(rados_completion_t c);
2004
2005 /**
2006 * Get the return value of an asychronous operation
2007 *
2008 * The return value is set when the operation is complete or safe,
2009 * whichever comes first.
2010 *
2011 * @pre The operation is safe or complete
2012 *
2013 * @note BUG: complete callback may never be called when the safe
2014 * message is received before the complete message
2015 *
2016 * @param c async operation to inspect
2017 * @returns return value of the operation
2018 */
2019 CEPH_RADOS_API int rados_aio_get_return_value(rados_completion_t c);
2020
2021 /**
2022 * Get the internal object version of the target of an asychronous operation
2023 *
2024 * The return value is set when the operation is complete or safe,
2025 * whichever comes first.
2026 *
2027 * @pre The operation is safe or complete
2028 *
2029 * @note BUG: complete callback may never be called when the safe
2030 * message is received before the complete message
2031 *
2032 * @param c async operation to inspect
2033 * @returns version number of the asychronous operation's target
2034 */
2035 CEPH_RADOS_API uint64_t rados_aio_get_version(rados_completion_t c);
2036
2037 /**
2038 * Release a completion
2039 *
2040 * Call this when you no longer need the completion. It may not be
2041 * freed immediately if the operation is not acked and committed.
2042 *
2043 * @param c completion to release
2044 */
2045 CEPH_RADOS_API void rados_aio_release(rados_completion_t c);
2046
2047 /**
2048 * Write data to an object asynchronously
2049 *
2050 * Queues the write and returns. The return value of the completion
2051 * will be 0 on success, negative error code on failure.
2052 *
2053 * @param io the context in which the write will occur
2054 * @param oid name of the object
2055 * @param completion what to do when the write is safe and complete
2056 * @param buf data to write
2057 * @param len length of the data, in bytes
2058 * @param off byte offset in the object to begin writing at
2059 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
2060 * other than LIBRADOS_SNAP_HEAD
2061 */
2062 CEPH_RADOS_API int rados_aio_write(rados_ioctx_t io, const char *oid,
2063 rados_completion_t completion,
2064 const char *buf, size_t len, uint64_t off);
2065
2066 /**
2067 * Asynchronously append data to an object
2068 *
2069 * Queues the append and returns.
2070 *
2071 * The return value of the completion will be 0 on success, negative
2072 * error code on failure.
2073 *
2074 * @param io the context to operate in
2075 * @param oid the name of the object
2076 * @param completion what to do when the append is safe and complete
2077 * @param buf the data to append
2078 * @param len length of buf (in bytes)
2079 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
2080 * other than LIBRADOS_SNAP_HEAD
2081 */
2082 CEPH_RADOS_API int rados_aio_append(rados_ioctx_t io, const char *oid,
2083 rados_completion_t completion,
2084 const char *buf, size_t len);
2085
2086 /**
2087 * Asynchronously write an entire object
2088 *
2089 * The object is filled with the provided data. If the object exists,
2090 * it is atomically truncated and then written.
2091 * Queues the write_full and returns.
2092 *
2093 * The return value of the completion will be 0 on success, negative
2094 * error code on failure.
2095 *
2096 * @param io the io context in which the write will occur
2097 * @param oid name of the object
2098 * @param completion what to do when the write_full is safe and complete
2099 * @param buf data to write
2100 * @param len length of the data, in bytes
2101 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
2102 * other than LIBRADOS_SNAP_HEAD
2103 */
2104 CEPH_RADOS_API int rados_aio_write_full(rados_ioctx_t io, const char *oid,
2105 rados_completion_t completion,
2106 const char *buf, size_t len);
2107
2108 /**
2109 * Asynchronously write the same buffer multiple times
2110 *
2111 * Queues the writesame and returns.
2112 *
2113 * The return value of the completion will be 0 on success, negative
2114 * error code on failure.
2115 *
2116 * @param io the io context in which the write will occur
2117 * @param oid name of the object
2118 * @param completion what to do when the writesame is safe and complete
2119 * @param buf data to write
2120 * @param data_len length of the data, in bytes
2121 * @param write_len the total number of bytes to write
2122 * @param off byte offset in the object to begin writing at
2123 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
2124 * other than LIBRADOS_SNAP_HEAD
2125 */
2126 CEPH_RADOS_API int rados_aio_writesame(rados_ioctx_t io, const char *oid,
2127 rados_completion_t completion,
2128 const char *buf, size_t data_len,
2129 size_t write_len, uint64_t off);
2130
2131 /**
2132 * Asynchronously remove an object
2133 *
2134 * Queues the remove and returns.
2135 *
2136 * The return value of the completion will be 0 on success, negative
2137 * error code on failure.
2138 *
2139 * @param io the context to operate in
2140 * @param oid the name of the object
2141 * @param completion what to do when the remove is safe and complete
2142 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
2143 * other than LIBRADOS_SNAP_HEAD
2144 */
2145 CEPH_RADOS_API int rados_aio_remove(rados_ioctx_t io, const char *oid,
2146 rados_completion_t completion);
2147
2148 /**
2149 * Asynchronously read data from an object
2150 *
2151 * The io context determines the snapshot to read from, if any was set
2152 * by rados_ioctx_snap_set_read().
2153 *
2154 * The return value of the completion will be number of bytes read on
2155 * success, negative error code on failure.
2156 *
2157 * @note only the 'complete' callback of the completion will be called.
2158 *
2159 * @param io the context in which to perform the read
2160 * @param oid the name of the object to read from
2161 * @param completion what to do when the read is complete
2162 * @param buf where to store the results
2163 * @param len the number of bytes to read
2164 * @param off the offset to start reading from in the object
2165 * @returns 0 on success, negative error code on failure
2166 */
2167 CEPH_RADOS_API int rados_aio_read(rados_ioctx_t io, const char *oid,
2168 rados_completion_t completion,
2169 char *buf, size_t len, uint64_t off);
2170
2171 /**
2172 * Block until all pending writes in an io context are safe
2173 *
2174 * This is not equivalent to calling rados_aio_wait_for_safe() on all
2175 * write completions, since this waits for the associated callbacks to
2176 * complete as well.
2177 *
2178 * @note BUG: always returns 0, should be void or accept a timeout
2179 *
2180 * @param io the context to flush
2181 * @returns 0 on success, negative error code on failure
2182 */
2183 CEPH_RADOS_API int rados_aio_flush(rados_ioctx_t io);
2184
2185
2186 /**
2187 * Schedule a callback for when all currently pending
2188 * aio writes are safe. This is a non-blocking version of
2189 * rados_aio_flush().
2190 *
2191 * @param io the context to flush
2192 * @param completion what to do when the writes are safe
2193 * @returns 0 on success, negative error code on failure
2194 */
2195 CEPH_RADOS_API int rados_aio_flush_async(rados_ioctx_t io,
2196 rados_completion_t completion);
2197
2198
2199 /**
2200 * Asynchronously get object stats (size/mtime)
2201 *
2202 * @param io ioctx
2203 * @param o object name
2204 * @param completion what to do when the stat is complete
2205 * @param psize where to store object size
2206 * @param pmtime where to store modification time
2207 * @returns 0 on success, negative error code on failure
2208 */
2209 CEPH_RADOS_API int rados_aio_stat(rados_ioctx_t io, const char *o,
2210 rados_completion_t completion,
2211 uint64_t *psize, time_t *pmtime);
2212
2213 /**
2214 * Asynchronously compare an on-disk object range with a buffer
2215 *
2216 * @param io the context in which to perform the comparison
2217 * @param o the name of the object to compare with
2218 * @param completion what to do when the comparison is complete
2219 * @param cmp_buf buffer containing bytes to be compared with object contents
2220 * @param cmp_len length to compare and size of @c cmp_buf in bytes
2221 * @param off object byte offset at which to start the comparison
2222 * @returns 0 on success, negative error code on failure,
2223 * (-MAX_ERRNO - mismatch_off) on mismatch
2224 */
2225 CEPH_RADOS_API int rados_aio_cmpext(rados_ioctx_t io, const char *o,
2226 rados_completion_t completion,
2227 const char *cmp_buf,
2228 size_t cmp_len,
2229 uint64_t off);
2230
2231 /**
2232 * Cancel async operation
2233 *
2234 * @param io ioctx
2235 * @param completion completion handle
2236 * @returns 0 on success, negative error code on failure
2237 */
2238 CEPH_RADOS_API int rados_aio_cancel(rados_ioctx_t io,
2239 rados_completion_t completion);
2240
2241 /**
2242 * Asynchronously execute an OSD class method on an object
2243 *
2244 * The OSD has a plugin mechanism for performing complicated
2245 * operations on an object atomically. These plugins are called
2246 * classes. This function allows librados users to call the custom
2247 * methods. The input and output formats are defined by the class.
2248 * Classes in ceph.git can be found in src/cls subdirectories
2249 *
2250 * @param io the context in which to call the method
2251 * @param o name of the object
2252 * @param completion what to do when the exec completes
2253 * @param cls the name of the class
2254 * @param method the name of the method
2255 * @param in_buf where to find input
2256 * @param in_len length of in_buf in bytes
2257 * @param buf where to store output
2258 * @param out_len length of buf in bytes
2259 * @returns 0 on success, negative error code on failure
2260 */
2261 CEPH_RADOS_API int rados_aio_exec(rados_ioctx_t io, const char *o,
2262 rados_completion_t completion,
2263 const char *cls, const char *method,
2264 const char *in_buf, size_t in_len,
2265 char *buf, size_t out_len);
2266
2267 /** @} Asynchronous I/O */
2268
2269 /**
2270 * @name Asynchronous Xattrs
2271 * Extended attributes are stored as extended attributes on the files
2272 * representing an object on the OSDs. Thus, they have the same
2273 * limitations as the underlying filesystem. On ext4, this means that
2274 * the total data stored in xattrs cannot exceed 4KB.
2275 *
2276 * @{
2277 */
2278
2279 /**
2280 * Asynchronously get the value of an extended attribute on an object.
2281 *
2282 * @param io the context in which the attribute is read
2283 * @param o name of the object
2284 * @param completion what to do when the getxattr completes
2285 * @param name which extended attribute to read
2286 * @param buf where to store the result
2287 * @param len size of buf in bytes
2288 * @returns length of xattr value on success, negative error code on failure
2289 */
2290 CEPH_RADOS_API int rados_aio_getxattr(rados_ioctx_t io, const char *o,
2291 rados_completion_t completion,
2292 const char *name, char *buf, size_t len);
2293
2294 /**
2295 * Asynchronously set an extended attribute on an object.
2296 *
2297 * @param io the context in which xattr is set
2298 * @param o name of the object
2299 * @param completion what to do when the setxattr completes
2300 * @param name which extended attribute to set
2301 * @param buf what to store in the xattr
2302 * @param len the number of bytes in buf
2303 * @returns 0 on success, negative error code on failure
2304 */
2305 CEPH_RADOS_API int rados_aio_setxattr(rados_ioctx_t io, const char *o,
2306 rados_completion_t completion,
2307 const char *name, const char *buf,
2308 size_t len);
2309
2310 /**
2311 * Asynchronously delete an extended attribute from an object.
2312 *
2313 * @param io the context in which to delete the xattr
2314 * @param o the name of the object
2315 * @param completion what to do when the rmxattr completes
2316 * @param name which xattr to delete
2317 * @returns 0 on success, negative error code on failure
2318 */
2319 CEPH_RADOS_API int rados_aio_rmxattr(rados_ioctx_t io, const char *o,
2320 rados_completion_t completion,
2321 const char *name);
2322
2323 /**
2324 * Asynchronously start iterating over xattrs on an object.
2325 *
2326 * @post iter is a valid iterator
2327 *
2328 * @param io the context in which to list xattrs
2329 * @param oid name of the object
2330 * @param completion what to do when the getxattrs completes
2331 * @param iter where to store the iterator
2332 * @returns 0 on success, negative error code on failure
2333 */
2334 CEPH_RADOS_API int rados_aio_getxattrs(rados_ioctx_t io, const char *oid,
2335 rados_completion_t completion,
2336 rados_xattrs_iter_t *iter);
2337
2338 /** @} Asynchronous Xattrs */
2339
2340 /**
2341 * @name Watch/Notify
2342 *
2343 * Watch/notify is a protocol to help communicate among clients. It
2344 * can be used to sychronize client state. All that's needed is a
2345 * well-known object name (for example, rbd uses the header object of
2346 * an image).
2347 *
2348 * Watchers register an interest in an object, and receive all
2349 * notifies on that object. A notify attempts to communicate with all
2350 * clients watching an object, and blocks on the notifier until each
2351 * client responds or a timeout is reached.
2352 *
2353 * See rados_watch() and rados_notify() for more details.
2354 *
2355 * @{
2356 */
2357
2358 /**
2359 * @typedef rados_watchcb_t
2360 *
2361 * Callback activated when a notify is received on a watched
2362 * object.
2363 *
2364 * @param opcode undefined
2365 * @param ver version of the watched object
2366 * @param arg application-specific data
2367 *
2368 * @note BUG: opcode is an internal detail that shouldn't be exposed
2369 * @note BUG: ver is unused
2370 */
2371 typedef void (*rados_watchcb_t)(uint8_t opcode, uint64_t ver, void *arg);
2372
2373 /**
2374 * @typedef rados_watchcb2_t
2375 *
2376 * Callback activated when a notify is received on a watched
2377 * object.
2378 *
2379 * @param arg opaque user-defined value provided to rados_watch2()
2380 * @param notify_id an id for this notify event
2381 * @param handle the watcher handle we are notifying
2382 * @param notifier_id the unique client id for the notifier
2383 * @param data payload from the notifier
2384 * @param datalen length of payload buffer
2385 */
2386 typedef void (*rados_watchcb2_t)(void *arg,
2387 uint64_t notify_id,
2388 uint64_t handle,
2389 uint64_t notifier_id,
2390 void *data,
2391 size_t data_len);
2392
2393 /**
2394 * @typedef rados_watcherrcb_t
2395 *
2396 * Callback activated when we encounter an error with the watch session.
2397 * This can happen when the location of the objects moves within the
2398 * cluster and we fail to register our watch with the new object location,
2399 * or when our connection with the object OSD is otherwise interrupted and
2400 * we may have missed notify events.
2401 *
2402 * @param pre opaque user-defined value provided to rados_watch2()
2403 * @param err error code
2404 */
2405 typedef void (*rados_watcherrcb_t)(void *pre, uint64_t cookie, int err);
2406
2407 /**
2408 * Register an interest in an object
2409 *
2410 * A watch operation registers the client as being interested in
2411 * notifications on an object. OSDs keep track of watches on
2412 * persistent storage, so they are preserved across cluster changes by
2413 * the normal recovery process. If the client loses its connection to
2414 * the primary OSD for a watched object, the watch will be removed
2415 * after 30 seconds. Watches are automatically reestablished when a new
2416 * connection is made, or a placement group switches OSDs.
2417 *
2418 * @note BUG: librados should provide a way for watchers to notice connection resets
2419 * @note BUG: the ver parameter does not work, and -ERANGE will never be returned
2420 * (See URL tracker.ceph.com/issues/2592)
2421 *
2422 * @param io the pool the object is in
2423 * @param o the object to watch
2424 * @param ver expected version of the object
2425 * @param cookie where to store the internal id assigned to this watch
2426 * @param watchcb what to do when a notify is received on this object
2427 * @param arg application defined data to pass when watchcb is called
2428 * @returns 0 on success, negative error code on failure
2429 * @returns -ERANGE if the version of the object is greater than ver
2430 */
2431 CEPH_RADOS_API int rados_watch(rados_ioctx_t io, const char *o, uint64_t ver,
2432 uint64_t *cookie,
2433 rados_watchcb_t watchcb, void *arg)
2434 __attribute__((deprecated));
2435
2436
2437 /**
2438 * Register an interest in an object
2439 *
2440 * A watch operation registers the client as being interested in
2441 * notifications on an object. OSDs keep track of watches on
2442 * persistent storage, so they are preserved across cluster changes by
2443 * the normal recovery process. If the client loses its connection to the
2444 * primary OSD for a watched object, the watch will be removed after
2445 * a timeout configured with osd_client_watch_timeout.
2446 * Watches are automatically reestablished when a new
2447 * connection is made, or a placement group switches OSDs.
2448 *
2449 * @param io the pool the object is in
2450 * @param o the object to watch
2451 * @param cookie where to store the internal id assigned to this watch
2452 * @param watchcb what to do when a notify is received on this object
2453 * @param watcherrcb what to do when the watch session encounters an error
2454 * @param arg opaque value to pass to the callback
2455 * @returns 0 on success, negative error code on failure
2456 */
2457 CEPH_RADOS_API int rados_watch2(rados_ioctx_t io, const char *o, uint64_t *cookie,
2458 rados_watchcb2_t watchcb,
2459 rados_watcherrcb_t watcherrcb,
2460 void *arg);
2461
2462 /**
2463 * Register an interest in an object
2464 *
2465 * A watch operation registers the client as being interested in
2466 * notifications on an object. OSDs keep track of watches on
2467 * persistent storage, so they are preserved across cluster changes by
2468 * the normal recovery process. Watches are automatically reestablished when a new
2469 * connection is made, or a placement group switches OSDs.
2470 *
2471 * @param io the pool the object is in
2472 * @param o the object to watch
2473 * @param cookie where to store the internal id assigned to this watch
2474 * @param watchcb what to do when a notify is received on this object
2475 * @param watcherrcb what to do when the watch session encounters an error
2476 * @param timeout how many seconds the connection will keep after disconnection
2477 * @param arg opaque value to pass to the callback
2478 * @returns 0 on success, negative error code on failure
2479 */
2480 CEPH_RADOS_API int rados_watch3(rados_ioctx_t io, const char *o, uint64_t *cookie,
2481 rados_watchcb2_t watchcb,
2482 rados_watcherrcb_t watcherrcb,
2483 uint32_t timeout,
2484 void *arg);
2485
2486 /**
2487 * Asynchronous register an interest in an object
2488 *
2489 * A watch operation registers the client as being interested in
2490 * notifications on an object. OSDs keep track of watches on
2491 * persistent storage, so they are preserved across cluster changes by
2492 * the normal recovery process. If the client loses its connection to
2493 * the primary OSD for a watched object, the watch will be removed
2494 * after 30 seconds. Watches are automatically reestablished when a new
2495 * connection is made, or a placement group switches OSDs.
2496 *
2497 * @param io the pool the object is in
2498 * @param o the object to watch
2499 * @param completion what to do when operation has been attempted
2500 * @param handle where to store the internal id assigned to this watch
2501 * @param watchcb what to do when a notify is received on this object
2502 * @param watcherrcb what to do when the watch session encounters an error
2503 * @param arg opaque value to pass to the callback
2504 * @returns 0 on success, negative error code on failure
2505 */
2506 CEPH_RADOS_API int rados_aio_watch(rados_ioctx_t io, const char *o,
2507 rados_completion_t completion, uint64_t *handle,
2508 rados_watchcb2_t watchcb,
2509 rados_watcherrcb_t watcherrcb,
2510 void *arg);
2511
2512 /**
2513 * Asynchronous register an interest in an object
2514 *
2515 * A watch operation registers the client as being interested in
2516 * notifications on an object. OSDs keep track of watches on
2517 * persistent storage, so they are preserved across cluster changes by
2518 * the normal recovery process. If the client loses its connection to
2519 * the primary OSD for a watched object, the watch will be removed
2520 * after the number of seconds that configured in timeout parameter.
2521 * Watches are automatically reestablished when a new
2522 * connection is made, or a placement group switches OSDs.
2523 *
2524 * @param io the pool the object is in
2525 * @param o the object to watch
2526 * @param completion what to do when operation has been attempted
2527 * @param handle where to store the internal id assigned to this watch
2528 * @param watchcb what to do when a notify is received on this object
2529 * @param watcherrcb what to do when the watch session encounters an error
2530 * @param timeout how many seconds the connection will keep after disconnection
2531 * @param arg opaque value to pass to the callback
2532 * @returns 0 on success, negative error code on failure
2533 */
2534 CEPH_RADOS_API int rados_aio_watch2(rados_ioctx_t io, const char *o,
2535 rados_completion_t completion, uint64_t *handle,
2536 rados_watchcb2_t watchcb,
2537 rados_watcherrcb_t watcherrcb,
2538 uint32_t timeout,
2539 void *arg);
2540
2541 /**
2542 * Check on the status of a watch
2543 *
2544 * Return the number of milliseconds since the watch was last confirmed.
2545 * Or, if there has been an error, return that.
2546 *
2547 * If there is an error, the watch is no longer valid, and should be
2548 * destroyed with rados_unwatch2(). The the user is still interested
2549 * in the object, a new watch should be created with rados_watch2().
2550 *
2551 * @param io the pool the object is in
2552 * @param cookie the watch handle
2553 * @returns ms since last confirmed on success, negative error code on failure
2554 */
2555 CEPH_RADOS_API int rados_watch_check(rados_ioctx_t io, uint64_t cookie);
2556
2557 /**
2558 * Unregister an interest in an object
2559 *
2560 * Once this completes, no more notifies will be sent to us for this
2561 * watch. This should be called to clean up unneeded watchers.
2562 *
2563 * @param io the pool the object is in
2564 * @param o the name of the watched object (ignored)
2565 * @param cookie which watch to unregister
2566 * @returns 0 on success, negative error code on failure
2567 */
2568 CEPH_RADOS_API int rados_unwatch(rados_ioctx_t io, const char *o, uint64_t cookie)
2569 __attribute__((deprecated));
2570
2571 /**
2572 * Unregister an interest in an object
2573 *
2574 * Once this completes, no more notifies will be sent to us for this
2575 * watch. This should be called to clean up unneeded watchers.
2576 *
2577 * @param io the pool the object is in
2578 * @param cookie which watch to unregister
2579 * @returns 0 on success, negative error code on failure
2580 */
2581 CEPH_RADOS_API int rados_unwatch2(rados_ioctx_t io, uint64_t cookie);
2582
2583 /**
2584 * Asynchronous unregister an interest in an object
2585 *
2586 * Once this completes, no more notifies will be sent to us for this
2587 * watch. This should be called to clean up unneeded watchers.
2588 *
2589 * @param io the pool the object is in
2590 * @param completion what to do when operation has been attempted
2591 * @param cookie which watch to unregister
2592 * @returns 0 on success, negative error code on failure
2593 */
2594 CEPH_RADOS_API int rados_aio_unwatch(rados_ioctx_t io, uint64_t cookie,
2595 rados_completion_t completion);
2596
2597 /**
2598 * Sychronously notify watchers of an object
2599 *
2600 * This blocks until all watchers of the object have received and
2601 * reacted to the notify, or a timeout is reached.
2602 *
2603 * @note BUG: the timeout is not changeable via the C API
2604 * @note BUG: the bufferlist is inaccessible in a rados_watchcb_t
2605 *
2606 * @param io the pool the object is in
2607 * @param o the name of the object
2608 * @param ver obsolete - just pass zero
2609 * @param buf data to send to watchers
2610 * @param buf_len length of buf in bytes
2611 * @returns 0 on success, negative error code on failure
2612 */
2613 CEPH_RADOS_API int rados_notify(rados_ioctx_t io, const char *o, uint64_t ver,
2614 const char *buf, int buf_len)
2615 __attribute__((deprecated));
2616
2617 /**
2618 * Sychronously notify watchers of an object
2619 *
2620 * This blocks until all watchers of the object have received and
2621 * reacted to the notify, or a timeout is reached.
2622 *
2623 * The reply buffer is optional. If specified, the client will get
2624 * back an encoded buffer that includes the ids of the clients that
2625 * acknowledged the notify as well as their notify ack payloads (if
2626 * any). Clients that timed out are not included. Even clients that
2627 * do not include a notify ack payload are included in the list but
2628 * have a 0-length payload associated with them. The format:
2629 *
2630 * le32 num_acks
2631 * {
2632 * le64 gid global id for the client (for client.1234 that's 1234)
2633 * le64 cookie cookie for the client
2634 * le32 buflen length of reply message buffer
2635 * u8 * buflen payload
2636 * } * num_acks
2637 * le32 num_timeouts
2638 * {
2639 * le64 gid global id for the client
2640 * le64 cookie cookie for the client
2641 * } * num_timeouts
2642 *
2643 * Note: There may be multiple instances of the same gid if there are
2644 * multiple watchers registered via the same client.
2645 *
2646 * Note: The buffer must be released with rados_buffer_free() when the
2647 * user is done with it.
2648 *
2649 * Note: Since the result buffer includes clients that time out, it
2650 * will be set even when rados_notify() returns an error code (like
2651 * -ETIMEDOUT).
2652 *
2653 * @param io the pool the object is in
2654 * @param completion what to do when operation has been attempted
2655 * @param o the name of the object
2656 * @param buf data to send to watchers
2657 * @param buf_len length of buf in bytes
2658 * @param timeout_ms notify timeout (in ms)
2659 * @param reply_buffer pointer to reply buffer pointer (free with rados_buffer_free)
2660 * @param reply_buffer_len pointer to size of reply buffer
2661 * @returns 0 on success, negative error code on failure
2662 */
2663 CEPH_RADOS_API int rados_aio_notify(rados_ioctx_t io, const char *o,
2664 rados_completion_t completion,
2665 const char *buf, int buf_len,
2666 uint64_t timeout_ms, char **reply_buffer,
2667 size_t *reply_buffer_len);
2668 CEPH_RADOS_API int rados_notify2(rados_ioctx_t io, const char *o,
2669 const char *buf, int buf_len,
2670 uint64_t timeout_ms,
2671 char **reply_buffer, size_t *reply_buffer_len);
2672
2673 /**
2674 * Decode a notify response
2675 *
2676 * Decode a notify response (from rados_aio_notify() call) into acks and
2677 * timeout arrays.
2678 *
2679 * @param reply_buffer buffer from rados_aio_notify() call
2680 * @param reply_buffer_len reply_buffer length
2681 * @param acks pointer to struct notify_ack_t pointer
2682 * @param nr_acks pointer to ack count
2683 * @param timeouts pointer to notify_timeout_t pointer
2684 * @param nr_timeouts pointer to timeout count
2685 * @returns 0 on success
2686 */
2687 CEPH_RADOS_API int rados_decode_notify_response(char *reply_buffer, size_t reply_buffer_len,
2688 struct notify_ack_t **acks, size_t *nr_acks,
2689 struct notify_timeout_t **timeouts, size_t *nr_timeouts);
2690
2691 /**
2692 * Free notify allocated buffer
2693 *
2694 * Release memory allocated by rados_decode_notify_response() call
2695 *
2696 * @param acks notify_ack_t struct (from rados_decode_notify_response())
2697 * @param nr_acks ack count
2698 * @param timeouts notify_timeout_t struct (from rados_decode_notify_response())
2699 */
2700 CEPH_RADOS_API void rados_free_notify_response(struct notify_ack_t *acks, size_t nr_acks,
2701 struct notify_timeout_t *timeouts);
2702
2703 /**
2704 * Acknolwedge receipt of a notify
2705 *
2706 * @param io the pool the object is in
2707 * @param o the name of the object
2708 * @param notify_id the notify_id we got on the watchcb2_t callback
2709 * @param cookie the watcher handle
2710 * @param buf payload to return to notifier (optional)
2711 * @param buf_len payload length
2712 * @returns 0 on success
2713 */
2714 CEPH_RADOS_API int rados_notify_ack(rados_ioctx_t io, const char *o,
2715 uint64_t notify_id, uint64_t cookie,
2716 const char *buf, int buf_len);
2717
2718 /**
2719 * Flush watch/notify callbacks
2720 *
2721 * This call will block until all pending watch/notify callbacks have
2722 * been executed and the queue is empty. It should usually be called
2723 * after shutting down any watches before shutting down the ioctx or
2724 * librados to ensure that any callbacks do not misuse the ioctx (for
2725 * example by calling rados_notify_ack after the ioctx has been
2726 * destroyed).
2727 *
2728 * @param cluster the cluster handle
2729 */
2730 CEPH_RADOS_API int rados_watch_flush(rados_t cluster);
2731 /**
2732 * Flush watch/notify callbacks
2733 *
2734 * This call will be nonblock, and the completion will be called
2735 * until all pending watch/notify callbacks have been executed and
2736 * the queue is empty. It should usually be called after shutting
2737 * down any watches before shutting down the ioctx or
2738 * librados to ensure that any callbacks do not misuse the ioctx (for
2739 * example by calling rados_notify_ack after the ioctx has been
2740 * destroyed).
2741 *
2742 * @param cluster the cluster handle
2743 * @param completion what to do when operation has been attempted
2744 */
2745 CEPH_RADOS_API int rados_aio_watch_flush(rados_t cluster, rados_completion_t completion);
2746
2747 /** @} Watch/Notify */
2748
2749 /**
2750 * Pin an object in the cache tier
2751 *
2752 * When an object is pinned in the cache tier, it stays in the cache
2753 * tier, and won't be flushed out.
2754 *
2755 * @param io the pool the object is in
2756 * @param o the object id
2757 * @returns 0 on success, negative error code on failure
2758 */
2759 CEPH_RADOS_API int rados_cache_pin(rados_ioctx_t io, const char *o);
2760
2761 /**
2762 * Unpin an object in the cache tier
2763 *
2764 * After an object is unpinned in the cache tier, it can be flushed out
2765 *
2766 * @param io the pool the object is in
2767 * @param o the object id
2768 * @returns 0 on success, negative error code on failure
2769 */
2770 CEPH_RADOS_API int rados_cache_unpin(rados_ioctx_t io, const char *o);
2771
2772 /**
2773 * @name Hints
2774 *
2775 * @{
2776 */
2777
2778 /**
2779 * Set allocation hint for an object
2780 *
2781 * This is an advisory operation, it will always succeed (as if it was
2782 * submitted with a LIBRADOS_OP_FLAG_FAILOK flag set) and is not
2783 * guaranteed to do anything on the backend.
2784 *
2785 * @param io the pool the object is in
2786 * @param o the name of the object
2787 * @param expected_object_size expected size of the object, in bytes
2788 * @param expected_write_size expected size of writes to the object, in bytes
2789 * @returns 0 on success, negative error code on failure
2790 */
2791 CEPH_RADOS_API int rados_set_alloc_hint(rados_ioctx_t io, const char *o,
2792 uint64_t expected_object_size,
2793 uint64_t expected_write_size);
2794
2795 /**
2796 * Set allocation hint for an object
2797 *
2798 * This is an advisory operation, it will always succeed (as if it was
2799 * submitted with a LIBRADOS_OP_FLAG_FAILOK flag set) and is not
2800 * guaranteed to do anything on the backend.
2801 *
2802 * @param io the pool the object is in
2803 * @param o the name of the object
2804 * @param expected_object_size expected size of the object, in bytes
2805 * @param expected_write_size expected size of writes to the object, in bytes
2806 * @param flags hints about future IO patterns
2807 * @returns 0 on success, negative error code on failure
2808 */
2809 CEPH_RADOS_API int rados_set_alloc_hint2(rados_ioctx_t io, const char *o,
2810 uint64_t expected_object_size,
2811 uint64_t expected_write_size,
2812 uint32_t flags);
2813
2814 /** @} Hints */
2815
2816 /**
2817 * @name Object Operations
2818 *
2819 * A single rados operation can do multiple operations on one object
2820 * atomically. The whole operation will succeed or fail, and no partial
2821 * results will be visible.
2822 *
2823 * Operations may be either reads, which can return data, or writes,
2824 * which cannot. The effects of writes are applied and visible all at
2825 * once, so an operation that sets an xattr and then checks its value
2826 * will not see the updated value.
2827 *
2828 * @{
2829 */
2830
2831 /**
2832 * Create a new rados_write_op_t write operation. This will store all actions
2833 * to be performed atomically. You must call rados_release_write_op when you are
2834 * finished with it.
2835 *
2836 * @note the ownership of a write operartion is passed to the function
2837 * performing the operation, so the same instance of @c rados_write_op_t
2838 * cannot be used again after being performed.
2839 *
2840 * @returns non-NULL on success, NULL on memory allocation error.
2841 */
2842 CEPH_RADOS_API rados_write_op_t rados_create_write_op(void);
2843
2844 /**
2845 * Free a rados_write_op_t, must be called when you're done with it.
2846 * @param write_op operation to deallocate, created with rados_create_write_op
2847 */
2848 CEPH_RADOS_API void rados_release_write_op(rados_write_op_t write_op);
2849
2850 /**
2851 * Set flags for the last operation added to this write_op.
2852 * At least one op must have been added to the write_op.
2853 * @param write_op operation to add this action to
2854 * @param flags see librados.h constants beginning with LIBRADOS_OP_FLAG
2855 */
2856 CEPH_RADOS_API void rados_write_op_set_flags(rados_write_op_t write_op,
2857 int flags);
2858
2859 /**
2860 * Ensure that the object exists before writing
2861 * @param write_op operation to add this action to
2862 */
2863 CEPH_RADOS_API void rados_write_op_assert_exists(rados_write_op_t write_op);
2864
2865 /**
2866 * Ensure that the object exists and that its internal version
2867 * number is equal to "ver" before writing. "ver" should be a
2868 * version number previously obtained with rados_get_last_version().
2869 * - If the object's version is greater than the asserted version
2870 * then rados_write_op_operate will return -ERANGE instead of
2871 * executing the op.
2872 * - If the object's version is less than the asserted version
2873 * then rados_write_op_operate will return -EOVERFLOW instead
2874 * of executing the op.
2875 * @param write_op operation to add this action to
2876 * @param ver object version number
2877 */
2878 CEPH_RADOS_API void rados_write_op_assert_version(rados_write_op_t write_op, uint64_t ver);
2879
2880 /**
2881 * Ensure that given object range (extent) satisfies comparison.
2882 *
2883 * @param write_op operation to add this action to
2884 * @param cmp_buf buffer containing bytes to be compared with object contents
2885 * @param cmp_len length to compare and size of @c cmp_buf in bytes
2886 * @param off object byte offset at which to start the comparison
2887 * @param prval returned result of comparison, 0 on success, negative error code
2888 * on failure, (-MAX_ERRNO - mismatch_off) on mismatch
2889 */
2890 CEPH_RADOS_API void rados_write_op_cmpext(rados_write_op_t write_op,
2891 const char *cmp_buf,
2892 size_t cmp_len,
2893 uint64_t off,
2894 int *prval);
2895
2896 /**
2897 * Ensure that given xattr satisfies comparison.
2898 * If the comparison is not satisfied, the return code of the
2899 * operation will be -ECANCELED
2900 * @param write_op operation to add this action to
2901 * @param name name of the xattr to look up
2902 * @param comparison_operator currently undocumented, look for
2903 * LIBRADOS_CMPXATTR_OP_EQ in librados.h
2904 * @param value buffer to compare actual xattr value to
2905 * @param value_len length of buffer to compare actual xattr value to
2906 */
2907 CEPH_RADOS_API void rados_write_op_cmpxattr(rados_write_op_t write_op,
2908 const char *name,
2909 uint8_t comparison_operator,
2910 const char *value,
2911 size_t value_len);
2912
2913 /**
2914 * Ensure that the an omap value satisfies a comparison,
2915 * with the supplied value on the right hand side (i.e.
2916 * for OP_LT, the comparison is actual_value < value.
2917 *
2918 * @param write_op operation to add this action to
2919 * @param key which omap value to compare
2920 * @param comparison_operator one of LIBRADOS_CMPXATTR_OP_EQ,
2921 LIBRADOS_CMPXATTR_OP_LT, or LIBRADOS_CMPXATTR_OP_GT
2922 * @param val value to compare with
2923 * @param val_len length of value in bytes
2924 * @param prval where to store the return value from this action
2925 */
2926 CEPH_RADOS_API void rados_write_op_omap_cmp(rados_write_op_t write_op,
2927 const char *key,
2928 uint8_t comparison_operator,
2929 const char *val,
2930 size_t val_len,
2931 int *prval);
2932
2933 /**
2934 * Ensure that the an omap value satisfies a comparison,
2935 * with the supplied value on the right hand side (i.e.
2936 * for OP_LT, the comparison is actual_value < value.
2937 *
2938 * @param write_op operation to add this action to
2939 * @param key which omap value to compare
2940 * @param comparison_operator one of LIBRADOS_CMPXATTR_OP_EQ,
2941 LIBRADOS_CMPXATTR_OP_LT, or LIBRADOS_CMPXATTR_OP_GT
2942 * @param val value to compare with
2943 * @param key_len length of key in bytes
2944 * @param val_len length of value in bytes
2945 * @param prval where to store the return value from this action
2946 */
2947 CEPH_RADOS_API void rados_write_op_omap_cmp2(rados_write_op_t write_op,
2948 const char *key,
2949 uint8_t comparison_operator,
2950 const char *val,
2951 size_t key_len,
2952 size_t val_len,
2953 int *prval);
2954
2955 /**
2956 * Set an xattr
2957 * @param write_op operation to add this action to
2958 * @param name name of the xattr
2959 * @param value buffer to set xattr to
2960 * @param value_len length of buffer to set xattr to
2961 */
2962 CEPH_RADOS_API void rados_write_op_setxattr(rados_write_op_t write_op,
2963 const char *name,
2964 const char *value,
2965 size_t value_len);
2966
2967 /**
2968 * Remove an xattr
2969 * @param write_op operation to add this action to
2970 * @param name name of the xattr to remove
2971 */
2972 CEPH_RADOS_API void rados_write_op_rmxattr(rados_write_op_t write_op,
2973 const char *name);
2974
2975 /**
2976 * Create the object
2977 * @param write_op operation to add this action to
2978 * @param exclusive set to either LIBRADOS_CREATE_EXCLUSIVE or
2979 LIBRADOS_CREATE_IDEMPOTENT
2980 * will error if the object already exists.
2981 * @param category category string (DEPRECATED, HAS NO EFFECT)
2982 */
2983 CEPH_RADOS_API void rados_write_op_create(rados_write_op_t write_op,
2984 int exclusive,
2985 const char* category);
2986
2987 /**
2988 * Write to offset
2989 * @param write_op operation to add this action to
2990 * @param offset offset to write to
2991 * @param buffer bytes to write
2992 * @param len length of buffer
2993 */
2994 CEPH_RADOS_API void rados_write_op_write(rados_write_op_t write_op,
2995 const char *buffer,
2996 size_t len,
2997 uint64_t offset);
2998
2999 /**
3000 * Write whole object, atomically replacing it.
3001 * @param write_op operation to add this action to
3002 * @param buffer bytes to write
3003 * @param len length of buffer
3004 */
3005 CEPH_RADOS_API void rados_write_op_write_full(rados_write_op_t write_op,
3006 const char *buffer,
3007 size_t len);
3008
3009 /**
3010 * Write the same buffer multiple times
3011 * @param write_op operation to add this action to
3012 * @param buffer bytes to write
3013 * @param data_len length of buffer
3014 * @param write_len total number of bytes to write, as a multiple of @c data_len
3015 * @param offset offset to write to
3016 */
3017 CEPH_RADOS_API void rados_write_op_writesame(rados_write_op_t write_op,
3018 const char *buffer,
3019 size_t data_len,
3020 size_t write_len,
3021 uint64_t offset);
3022
3023 /**
3024 * Append to end of object.
3025 * @param write_op operation to add this action to
3026 * @param buffer bytes to write
3027 * @param len length of buffer
3028 */
3029 CEPH_RADOS_API void rados_write_op_append(rados_write_op_t write_op,
3030 const char *buffer,
3031 size_t len);
3032 /**
3033 * Remove object
3034 * @param write_op operation to add this action to
3035 */
3036 CEPH_RADOS_API void rados_write_op_remove(rados_write_op_t write_op);
3037
3038 /**
3039 * Truncate an object
3040 * @param write_op operation to add this action to
3041 * @param offset Offset to truncate to
3042 */
3043 CEPH_RADOS_API void rados_write_op_truncate(rados_write_op_t write_op,
3044 uint64_t offset);
3045
3046 /**
3047 * Zero part of an object
3048 * @param write_op operation to add this action to
3049 * @param offset Offset to zero
3050 * @param len length to zero
3051 */
3052 CEPH_RADOS_API void rados_write_op_zero(rados_write_op_t write_op,
3053 uint64_t offset,
3054 uint64_t len);
3055
3056 /**
3057 * Execute an OSD class method on an object
3058 * See rados_exec() for general description.
3059 *
3060 * @param write_op operation to add this action to
3061 * @param cls the name of the class
3062 * @param method the name of the method
3063 * @param in_buf where to find input
3064 * @param in_len length of in_buf in bytes
3065 * @param prval where to store the return value from the method
3066 */
3067 CEPH_RADOS_API void rados_write_op_exec(rados_write_op_t write_op,
3068 const char *cls,
3069 const char *method,
3070 const char *in_buf,
3071 size_t in_len,
3072 int *prval);
3073
3074 /**
3075 * Set key/value pairs on an object
3076 *
3077 * @param write_op operation to add this action to
3078 * @param keys array of null-terminated char arrays representing keys to set
3079 * @param vals array of pointers to values to set
3080 * @param lens array of lengths corresponding to each value
3081 * @param num number of key/value pairs to set
3082 */
3083 CEPH_RADOS_API void rados_write_op_omap_set(rados_write_op_t write_op,
3084 char const* const* keys,
3085 char const* const* vals,
3086 const size_t *lens,
3087 size_t num);
3088
3089 /**
3090 * Set key/value pairs on an object
3091 *
3092 * @param write_op operation to add this action to
3093 * @param keys array of null-terminated char arrays representing keys to set
3094 * @param vals array of pointers to values to set
3095 * @param key_lens array of lengths corresponding to each key
3096 * @param val_lens array of lengths corresponding to each value
3097 * @param num number of key/value pairs to set
3098 */
3099 CEPH_RADOS_API void rados_write_op_omap_set2(rados_write_op_t write_op,
3100 char const* const* keys,
3101 char const* const* vals,
3102 const size_t *key_lens,
3103 const size_t *val_lens,
3104 size_t num);
3105
3106 /**
3107 * Remove key/value pairs from an object
3108 *
3109 * @param write_op operation to add this action to
3110 * @param keys array of null-terminated char arrays representing keys to remove
3111 * @param keys_len number of key/value pairs to remove
3112 */
3113 CEPH_RADOS_API void rados_write_op_omap_rm_keys(rados_write_op_t write_op,
3114 char const* const* keys,
3115 size_t keys_len);
3116
3117 /**
3118 * Remove key/value pairs from an object
3119 *
3120 * @param write_op operation to add this action to
3121 * @param keys array of char arrays representing keys to remove
3122 * @param key_lens array of size_t values representing length of each key
3123 * @param keys_len number of key/value pairs to remove
3124 */
3125 CEPH_RADOS_API void rados_write_op_omap_rm_keys2(rados_write_op_t write_op,
3126 char const* const* keys,
3127 const size_t* key_lens,
3128 size_t keys_len);
3129
3130
3131 /**
3132 * Remove key/value pairs from an object whose keys are in the range
3133 * [key_begin, key_end)
3134 *
3135 * @param write_op operation to add this action to
3136 * @param key_begin the lower bound of the key range to remove
3137 * @param key_begin_len length of key_begin
3138 * @param key_end the upper bound of the key range to remove
3139 * @param key_end_len length of key_end
3140 */
3141 CEPH_RADOS_API void rados_write_op_omap_rm_range2(rados_write_op_t write_op,
3142 const char *key_begin,
3143 size_t key_begin_len,
3144 const char *key_end,
3145 size_t key_end_len);
3146
3147 /**
3148 * Remove all key/value pairs from an object
3149 *
3150 * @param write_op operation to add this action to
3151 */
3152 CEPH_RADOS_API void rados_write_op_omap_clear(rados_write_op_t write_op);
3153
3154 /**
3155 * Set allocation hint for an object
3156 *
3157 * @param write_op operation to add this action to
3158 * @param expected_object_size expected size of the object, in bytes
3159 * @param expected_write_size expected size of writes to the object, in bytes
3160 */
3161 CEPH_RADOS_API void rados_write_op_set_alloc_hint(rados_write_op_t write_op,
3162 uint64_t expected_object_size,
3163 uint64_t expected_write_size);
3164
3165 /**
3166 * Set allocation hint for an object
3167 *
3168 * @param write_op operation to add this action to
3169 * @param expected_object_size expected size of the object, in bytes
3170 * @param expected_write_size expected size of writes to the object, in bytes
3171 * @param flags hints about future IO patterns
3172 */
3173 CEPH_RADOS_API void rados_write_op_set_alloc_hint2(rados_write_op_t write_op,
3174 uint64_t expected_object_size,
3175 uint64_t expected_write_size,
3176 uint32_t flags);
3177
3178 /**
3179 * Perform a write operation synchronously
3180 * @param write_op operation to perform
3181 * @param io the ioctx that the object is in
3182 * @param oid the object id
3183 * @param mtime the time to set the mtime to, NULL for the current time
3184 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
3185 */
3186 CEPH_RADOS_API int rados_write_op_operate(rados_write_op_t write_op,
3187 rados_ioctx_t io,
3188 const char *oid,
3189 time_t *mtime,
3190 int flags);
3191 /**
3192 * Perform a write operation synchronously
3193 * @param write_op operation to perform
3194 * @param io the ioctx that the object is in
3195 * @param oid the object id
3196 * @param mtime the time to set the mtime to, NULL for the current time
3197 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
3198 */
3199
3200 CEPH_RADOS_API int rados_write_op_operate2(rados_write_op_t write_op,
3201 rados_ioctx_t io,
3202 const char *oid,
3203 struct timespec *mtime,
3204 int flags);
3205
3206 /**
3207 * Perform a write operation asynchronously
3208 * @param write_op operation to perform
3209 * @param io the ioctx that the object is in
3210 * @param completion what to do when operation has been attempted
3211 * @param oid the object id
3212 * @param mtime the time to set the mtime to, NULL for the current time
3213 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
3214 */
3215 CEPH_RADOS_API int rados_aio_write_op_operate(rados_write_op_t write_op,
3216 rados_ioctx_t io,
3217 rados_completion_t completion,
3218 const char *oid,
3219 time_t *mtime,
3220 int flags);
3221
3222 /**
3223 * Create a new rados_read_op_t read operation. This will store all
3224 * actions to be performed atomically. You must call
3225 * rados_release_read_op when you are finished with it (after it
3226 * completes, or you decide not to send it in the first place).
3227 *
3228 * @note the ownership of a read operartion is passed to the function
3229 * performing the operation, so the same instance of @c rados_read_op_t
3230 * cannot be used again after being performed.
3231 *
3232 * @returns non-NULL on success, NULL on memory allocation error.
3233 */
3234 CEPH_RADOS_API rados_read_op_t rados_create_read_op(void);
3235
3236 /**
3237 * Free a rados_read_op_t, must be called when you're done with it.
3238 * @param read_op operation to deallocate, created with rados_create_read_op
3239 */
3240 CEPH_RADOS_API void rados_release_read_op(rados_read_op_t read_op);
3241
3242 /**
3243 * Set flags for the last operation added to this read_op.
3244 * At least one op must have been added to the read_op.
3245 * @param read_op operation to add this action to
3246 * @param flags see librados.h constants beginning with LIBRADOS_OP_FLAG
3247 */
3248 CEPH_RADOS_API void rados_read_op_set_flags(rados_read_op_t read_op, int flags);
3249
3250 /**
3251 * Ensure that the object exists before reading
3252 * @param read_op operation to add this action to
3253 */
3254 CEPH_RADOS_API void rados_read_op_assert_exists(rados_read_op_t read_op);
3255
3256 /**
3257 * Ensure that the object exists and that its internal version
3258 * number is equal to "ver" before reading. "ver" should be a
3259 * version number previously obtained with rados_get_last_version().
3260 * - If the object's version is greater than the asserted version
3261 * then rados_read_op_operate will return -ERANGE instead of
3262 * executing the op.
3263 * - If the object's version is less than the asserted version
3264 * then rados_read_op_operate will return -EOVERFLOW instead
3265 * of executing the op.
3266 * @param read_op operation to add this action to
3267 * @param ver object version number
3268 */
3269 CEPH_RADOS_API void rados_read_op_assert_version(rados_read_op_t read_op, uint64_t ver);
3270
3271 /**
3272 * Ensure that given object range (extent) satisfies comparison.
3273 *
3274 * @param read_op operation to add this action to
3275 * @param cmp_buf buffer containing bytes to be compared with object contents
3276 * @param cmp_len length to compare and size of @c cmp_buf in bytes
3277 * @param off object byte offset at which to start the comparison
3278 * @param prval returned result of comparison, 0 on success, negative error code
3279 * on failure, (-MAX_ERRNO - mismatch_off) on mismatch
3280 */
3281 CEPH_RADOS_API void rados_read_op_cmpext(rados_read_op_t read_op,
3282 const char *cmp_buf,
3283 size_t cmp_len,
3284 uint64_t off,
3285 int *prval);
3286
3287 /**
3288 * Ensure that the an xattr satisfies a comparison
3289 * If the comparison is not satisfied, the return code of the
3290 * operation will be -ECANCELED
3291 * @param read_op operation to add this action to
3292 * @param name name of the xattr to look up
3293 * @param comparison_operator currently undocumented, look for
3294 * LIBRADOS_CMPXATTR_OP_EQ in librados.h
3295 * @param value buffer to compare actual xattr value to
3296 * @param value_len length of buffer to compare actual xattr value to
3297 */
3298 CEPH_RADOS_API void rados_read_op_cmpxattr(rados_read_op_t read_op,
3299 const char *name,
3300 uint8_t comparison_operator,
3301 const char *value,
3302 size_t value_len);
3303
3304 /**
3305 * Start iterating over xattrs on an object.
3306 *
3307 * @param read_op operation to add this action to
3308 * @param iter where to store the iterator
3309 * @param prval where to store the return value of this action
3310 */
3311 CEPH_RADOS_API void rados_read_op_getxattrs(rados_read_op_t read_op,
3312 rados_xattrs_iter_t *iter,
3313 int *prval);
3314
3315 /**
3316 * Ensure that the an omap value satisfies a comparison,
3317 * with the supplied value on the right hand side (i.e.
3318 * for OP_LT, the comparison is actual_value < value.
3319 *
3320 * @param read_op operation to add this action to
3321 * @param key which omap value to compare
3322 * @param comparison_operator one of LIBRADOS_CMPXATTR_OP_EQ,
3323 LIBRADOS_CMPXATTR_OP_LT, or LIBRADOS_CMPXATTR_OP_GT
3324 * @param val value to compare with
3325 * @param val_len length of value in bytes
3326 * @param prval where to store the return value from this action
3327 */
3328 CEPH_RADOS_API void rados_read_op_omap_cmp(rados_read_op_t read_op,
3329 const char *key,
3330 uint8_t comparison_operator,
3331 const char *val,
3332 size_t val_len,
3333 int *prval);
3334
3335 /**
3336 * Ensure that the an omap value satisfies a comparison,
3337 * with the supplied value on the right hand side (i.e.
3338 * for OP_LT, the comparison is actual_value < value.
3339 *
3340 * @param read_op operation to add this action to
3341 * @param key which omap value to compare
3342 * @param comparison_operator one of LIBRADOS_CMPXATTR_OP_EQ,
3343 LIBRADOS_CMPXATTR_OP_LT, or LIBRADOS_CMPXATTR_OP_GT
3344 * @param val value to compare with
3345 * @param key_len length of key in bytes
3346 * @param val_len length of value in bytes
3347 * @param prval where to store the return value from this action
3348 */
3349 CEPH_RADOS_API void rados_read_op_omap_cmp2(rados_read_op_t read_op,
3350 const char *key,
3351 uint8_t comparison_operator,
3352 const char *val,
3353 size_t key_len,
3354 size_t val_len,
3355 int *prval);
3356
3357 /**
3358 * Get object size and mtime
3359 * @param read_op operation to add this action to
3360 * @param psize where to store object size
3361 * @param pmtime where to store modification time
3362 * @param prval where to store the return value of this action
3363 */
3364 CEPH_RADOS_API void rados_read_op_stat(rados_read_op_t read_op,
3365 uint64_t *psize,
3366 time_t *pmtime,
3367 int *prval);
3368
3369 /**
3370 * Read bytes from offset into buffer.
3371 *
3372 * prlen will be filled with the number of bytes read if successful.
3373 * A short read can only occur if the read reaches the end of the
3374 * object.
3375 *
3376 * @param read_op operation to add this action to
3377 * @param offset offset to read from
3378 * @param len length of buffer
3379 * @param buffer where to put the data
3380 * @param bytes_read where to store the number of bytes read by this action
3381 * @param prval where to store the return value of this action
3382 */
3383 CEPH_RADOS_API void rados_read_op_read(rados_read_op_t read_op,
3384 uint64_t offset,
3385 size_t len,
3386 char *buffer,
3387 size_t *bytes_read,
3388 int *prval);
3389
3390 /**
3391 * Compute checksum from object data
3392 *
3393 * @param read_op operation to add this action to
3394 * @param type the checksum algorithm to utilize
3395 * @param init_value the init value for the algorithm
3396 * @param init_value_len the length of the init value
3397 * @param offset the offset to start checksumming in the object
3398 * @param len the number of bytes to checksum
3399 * @param chunk_size optional length-aligned chunk size for checksums
3400 * @param pchecksum where to store the checksum result for this action
3401 * @param checksum_len the number of bytes available for the result
3402 * @param prval where to store the return value for this action
3403 */
3404 CEPH_RADOS_API void rados_read_op_checksum(rados_read_op_t read_op,
3405 rados_checksum_type_t type,
3406 const char *init_value,
3407 size_t init_value_len,
3408 uint64_t offset, size_t len,
3409 size_t chunk_size, char *pchecksum,
3410 size_t checksum_len, int *prval);
3411
3412 /**
3413 * Execute an OSD class method on an object
3414 * See rados_exec() for general description.
3415 *
3416 * The output buffer is allocated on the heap; the caller is
3417 * expected to release that memory with rados_buffer_free(). The
3418 * buffer and length pointers can all be NULL, in which case they are
3419 * not filled in.
3420 *
3421 * @param read_op operation to add this action to
3422 * @param cls the name of the class
3423 * @param method the name of the method
3424 * @param in_buf where to find input
3425 * @param in_len length of in_buf in bytes
3426 * @param out_buf where to put librados-allocated output buffer
3427 * @param out_len length of out_buf in bytes
3428 * @param prval where to store the return value from the method
3429 */
3430 CEPH_RADOS_API void rados_read_op_exec(rados_read_op_t read_op,
3431 const char *cls,
3432 const char *method,
3433 const char *in_buf,
3434 size_t in_len,
3435 char **out_buf,
3436 size_t *out_len,
3437 int *prval);
3438
3439 /**
3440 * Execute an OSD class method on an object
3441 * See rados_exec() for general description.
3442 *
3443 * If the output buffer is too small, prval will
3444 * be set to -ERANGE and used_len will be 0.
3445 *
3446 * @param read_op operation to add this action to
3447 * @param cls the name of the class
3448 * @param method the name of the method
3449 * @param in_buf where to find input
3450 * @param in_len length of in_buf in bytes
3451 * @param out_buf user-provided buffer to read into
3452 * @param out_len length of out_buf in bytes
3453 * @param used_len where to store the number of bytes read into out_buf
3454 * @param prval where to store the return value from the method
3455 */
3456 CEPH_RADOS_API void rados_read_op_exec_user_buf(rados_read_op_t read_op,
3457 const char *cls,
3458 const char *method,
3459 const char *in_buf,
3460 size_t in_len,
3461 char *out_buf,
3462 size_t out_len,
3463 size_t *used_len,
3464 int *prval);
3465
3466 /**
3467 * Start iterating over key/value pairs on an object.
3468 *
3469 * They will be returned sorted by key.
3470 *
3471 * @param read_op operation to add this action to
3472 * @param start_after list keys starting after start_after
3473 * @param filter_prefix list only keys beginning with filter_prefix
3474 * @param max_return list no more than max_return key/value pairs
3475 * @param iter where to store the iterator
3476 * @param prval where to store the return value from this action
3477 */
3478 CEPH_RADOS_API void rados_read_op_omap_get_vals(rados_read_op_t read_op,
3479 const char *start_after,
3480 const char *filter_prefix,
3481 uint64_t max_return,
3482 rados_omap_iter_t *iter,
3483 int *prval)
3484 __attribute__((deprecated)); /* use v2 below */
3485
3486 /**
3487 * Start iterating over key/value pairs on an object.
3488 *
3489 * They will be returned sorted by key.
3490 *
3491 * @param read_op operation to add this action to
3492 * @param start_after list keys starting after start_after
3493 * @param filter_prefix list only keys beginning with filter_prefix
3494 * @param max_return list no more than max_return key/value pairs
3495 * @param iter where to store the iterator
3496 * @param pmore flag indicating whether there are more keys to fetch
3497 * @param prval where to store the return value from this action
3498 */
3499 CEPH_RADOS_API void rados_read_op_omap_get_vals2(rados_read_op_t read_op,
3500 const char *start_after,
3501 const char *filter_prefix,
3502 uint64_t max_return,
3503 rados_omap_iter_t *iter,
3504 unsigned char *pmore,
3505 int *prval);
3506
3507 /**
3508 * Start iterating over keys on an object.
3509 *
3510 * They will be returned sorted by key, and the iterator
3511 * will fill in NULL for all values if specified.
3512 *
3513 * @param read_op operation to add this action to
3514 * @param start_after list keys starting after start_after
3515 * @param max_return list no more than max_return keys
3516 * @param iter where to store the iterator
3517 * @param prval where to store the return value from this action
3518 */
3519 CEPH_RADOS_API void rados_read_op_omap_get_keys(rados_read_op_t read_op,
3520 const char *start_after,
3521 uint64_t max_return,
3522 rados_omap_iter_t *iter,
3523 int *prval)
3524 __attribute__((deprecated)); /* use v2 below */
3525
3526 /**
3527 * Start iterating over keys on an object.
3528 *
3529 * They will be returned sorted by key, and the iterator
3530 * will fill in NULL for all values if specified.
3531 *
3532 * @param read_op operation to add this action to
3533 * @param start_after list keys starting after start_after
3534 * @param max_return list no more than max_return keys
3535 * @param iter where to store the iterator
3536 * @param pmore flag indicating whether there are more keys to fetch
3537 * @param prval where to store the return value from this action
3538 */
3539 CEPH_RADOS_API void rados_read_op_omap_get_keys2(rados_read_op_t read_op,
3540 const char *start_after,
3541 uint64_t max_return,
3542 rados_omap_iter_t *iter,
3543 unsigned char *pmore,
3544 int *prval);
3545
3546 /**
3547 * Start iterating over specific key/value pairs
3548 *
3549 * They will be returned sorted by key.
3550 *
3551 * @param read_op operation to add this action to
3552 * @param keys array of pointers to null-terminated keys to get
3553 * @param keys_len the number of strings in keys
3554 * @param iter where to store the iterator
3555 * @param prval where to store the return value from this action
3556 */
3557 CEPH_RADOS_API void rados_read_op_omap_get_vals_by_keys(rados_read_op_t read_op,
3558 char const* const* keys,
3559 size_t keys_len,
3560 rados_omap_iter_t *iter,
3561 int *prval);
3562
3563 /**
3564 * Start iterating over specific key/value pairs
3565 *
3566 * They will be returned sorted by key.
3567 *
3568 * @param read_op operation to add this action to
3569 * @param keys array of pointers to keys to get
3570 * @param num_keys the number of strings in keys
3571 * @param key_lens array of size_t's describing each key len (in bytes)
3572 * @param iter where to store the iterator
3573 * @param prval where to store the return value from this action
3574 */
3575 CEPH_RADOS_API void rados_read_op_omap_get_vals_by_keys2(rados_read_op_t read_op,
3576 char const* const* keys,
3577 size_t num_keys,
3578 const size_t* key_lens,
3579 rados_omap_iter_t *iter,
3580 int *prval);
3581
3582 /**
3583 * Perform a read operation synchronously
3584 * @param read_op operation to perform
3585 * @param io the ioctx that the object is in
3586 * @param oid the object id
3587 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
3588 */
3589 CEPH_RADOS_API int rados_read_op_operate(rados_read_op_t read_op,
3590 rados_ioctx_t io,
3591 const char *oid,
3592 int flags);
3593
3594 /**
3595 * Perform a read operation asynchronously
3596 * @param read_op operation to perform
3597 * @param io the ioctx that the object is in
3598 * @param completion what to do when operation has been attempted
3599 * @param oid the object id
3600 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
3601 */
3602 CEPH_RADOS_API int rados_aio_read_op_operate(rados_read_op_t read_op,
3603 rados_ioctx_t io,
3604 rados_completion_t completion,
3605 const char *oid,
3606 int flags);
3607
3608 /** @} Object Operations */
3609
3610 /**
3611 * Take an exclusive lock on an object.
3612 *
3613 * @param io the context to operate in
3614 * @param oid the name of the object
3615 * @param name the name of the lock
3616 * @param cookie user-defined identifier for this instance of the lock
3617 * @param desc user-defined lock description
3618 * @param duration the duration of the lock. Set to NULL for infinite duration.
3619 * @param flags lock flags
3620 * @returns 0 on success, negative error code on failure
3621 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
3622 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
3623 */
3624 CEPH_RADOS_API int rados_lock_exclusive(rados_ioctx_t io, const char * oid,
3625 const char * name, const char * cookie,
3626 const char * desc,
3627 struct timeval * duration,
3628 uint8_t flags);
3629
3630 /**
3631 * Take a shared lock on an object.
3632 *
3633 * @param io the context to operate in
3634 * @param o the name of the object
3635 * @param name the name of the lock
3636 * @param cookie user-defined identifier for this instance of the lock
3637 * @param tag The tag of the lock
3638 * @param desc user-defined lock description
3639 * @param duration the duration of the lock. Set to NULL for infinite duration.
3640 * @param flags lock flags
3641 * @returns 0 on success, negative error code on failure
3642 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
3643 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
3644 */
3645 CEPH_RADOS_API int rados_lock_shared(rados_ioctx_t io, const char * o,
3646 const char * name, const char * cookie,
3647 const char * tag, const char * desc,
3648 struct timeval * duration, uint8_t flags);
3649
3650 /**
3651 * Release a shared or exclusive lock on an object.
3652 *
3653 * @param io the context to operate in
3654 * @param o the name of the object
3655 * @param name the name of the lock
3656 * @param cookie user-defined identifier for the instance of the lock
3657 * @returns 0 on success, negative error code on failure
3658 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
3659 */
3660 CEPH_RADOS_API int rados_unlock(rados_ioctx_t io, const char *o,
3661 const char *name, const char *cookie);
3662
3663 /**
3664 * Asynchronous release a shared or exclusive lock on an object.
3665 *
3666 * @param io the context to operate in
3667 * @param o the name of the object
3668 * @param name the name of the lock
3669 * @param cookie user-defined identifier for the instance of the lock
3670 * @param completion what to do when operation has been attempted
3671 * @returns 0 on success, negative error code on failure
3672 */
3673 CEPH_RADOS_API int rados_aio_unlock(rados_ioctx_t io, const char *o,
3674 const char *name, const char *cookie,
3675 rados_completion_t completion);
3676
3677 /**
3678 * List clients that have locked the named object lock and information about
3679 * the lock.
3680 *
3681 * The number of bytes required in each buffer is put in the
3682 * corresponding size out parameter. If any of the provided buffers
3683 * are too short, -ERANGE is returned after these sizes are filled in.
3684 *
3685 * @param io the context to operate in
3686 * @param o the name of the object
3687 * @param name the name of the lock
3688 * @param exclusive where to store whether the lock is exclusive (1) or shared (0)
3689 * @param tag where to store the tag associated with the object lock
3690 * @param tag_len number of bytes in tag buffer
3691 * @param clients buffer in which locker clients are stored, separated by '\0'
3692 * @param clients_len number of bytes in the clients buffer
3693 * @param cookies buffer in which locker cookies are stored, separated by '\0'
3694 * @param cookies_len number of bytes in the cookies buffer
3695 * @param addrs buffer in which locker addresses are stored, separated by '\0'
3696 * @param addrs_len number of bytes in the clients buffer
3697 * @returns number of lockers on success, negative error code on failure
3698 * @returns -ERANGE if any of the buffers are too short
3699 */
3700 CEPH_RADOS_API ssize_t rados_list_lockers(rados_ioctx_t io, const char *o,
3701 const char *name, int *exclusive,
3702 char *tag, size_t *tag_len,
3703 char *clients, size_t *clients_len,
3704 char *cookies, size_t *cookies_len,
3705 char *addrs, size_t *addrs_len);
3706
3707 /**
3708 * Releases a shared or exclusive lock on an object, which was taken by the
3709 * specified client.
3710 *
3711 * @param io the context to operate in
3712 * @param o the name of the object
3713 * @param name the name of the lock
3714 * @param client the client currently holding the lock
3715 * @param cookie user-defined identifier for the instance of the lock
3716 * @returns 0 on success, negative error code on failure
3717 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
3718 * @returns -EINVAL if the client cannot be parsed
3719 */
3720 CEPH_RADOS_API int rados_break_lock(rados_ioctx_t io, const char *o,
3721 const char *name, const char *client,
3722 const char *cookie);
3723
3724 /**
3725 * Blocklists the specified client from the OSDs
3726 *
3727 * @param cluster cluster handle
3728 * @param client_address client address
3729 * @param expire_seconds number of seconds to blocklist (0 for default)
3730 * @returns 0 on success, negative error code on failure
3731 */
3732 CEPH_RADOS_API int rados_blocklist_add(rados_t cluster,
3733 char *client_address,
3734 uint32_t expire_seconds);
3735 CEPH_RADOS_API int rados_blacklist_add(rados_t cluster,
3736 char *client_address,
3737 uint32_t expire_seconds)
3738 __attribute__((deprecated));
3739
3740 /**
3741 * Gets addresses of the RADOS session, suitable for blocklisting.
3742 *
3743 * @param cluster cluster handle
3744 * @param addrs the output string.
3745 * @returns 0 on success, negative error code on failure
3746 */
3747 CEPH_RADOS_API int rados_getaddrs(rados_t cluster, char** addrs);
3748
3749 CEPH_RADOS_API void rados_set_osdmap_full_try(rados_ioctx_t io)
3750 __attribute__((deprecated));
3751
3752 CEPH_RADOS_API void rados_unset_osdmap_full_try(rados_ioctx_t io)
3753 __attribute__((deprecated));
3754
3755 CEPH_RADOS_API void rados_set_pool_full_try(rados_ioctx_t io);
3756
3757 CEPH_RADOS_API void rados_unset_pool_full_try(rados_ioctx_t io);
3758
3759 /**
3760 * Enable an application on a pool
3761 *
3762 * @param io pool ioctx
3763 * @param app_name application name
3764 * @param force 0 if only single application per pool
3765 * @returns 0 on success, negative error code on failure
3766 */
3767 CEPH_RADOS_API int rados_application_enable(rados_ioctx_t io,
3768 const char *app_name, int force);
3769
3770 /**
3771 * List all enabled applications
3772 *
3773 * If the provided buffer is too short, the required length is filled in and
3774 * -ERANGE is returned. Otherwise, the buffers are filled with the application
3775 * names, with a '\0' after each.
3776 *
3777 * @param io pool ioctx
3778 * @param values buffer in which to store application names
3779 * @param values_len number of bytes in values buffer
3780 * @returns 0 on success, negative error code on failure
3781 * @returns -ERANGE if either buffer is too short
3782 */
3783 CEPH_RADOS_API int rados_application_list(rados_ioctx_t io, char *values,
3784 size_t *values_len);
3785
3786 /**
3787 * Get application metadata value from pool
3788 *
3789 * @param io pool ioctx
3790 * @param app_name application name
3791 * @param key metadata key
3792 * @param value result buffer
3793 * @param value_len maximum len of value
3794 * @returns 0 on success, negative error code on failure
3795 */
3796 CEPH_RADOS_API int rados_application_metadata_get(rados_ioctx_t io,
3797 const char *app_name,
3798 const char *key, char *value,
3799 size_t *value_len);
3800
3801 /**
3802 * Set application metadata on a pool
3803 *
3804 * @param io pool ioctx
3805 * @param app_name application name
3806 * @param key metadata key
3807 * @param value metadata key
3808 * @returns 0 on success, negative error code on failure
3809 */
3810 CEPH_RADOS_API int rados_application_metadata_set(rados_ioctx_t io,
3811 const char *app_name,
3812 const char *key,
3813 const char *value);
3814
3815 /**
3816 * Remove application metadata from a pool
3817 *
3818 * @param io pool ioctx
3819 * @param app_name application name
3820 * @param key metadata key
3821 * @returns 0 on success, negative error code on failure
3822 */
3823 CEPH_RADOS_API int rados_application_metadata_remove(rados_ioctx_t io,
3824 const char *app_name,
3825 const char *key);
3826
3827 /**
3828 * List all metadata key/value pairs associated with an application.
3829 *
3830 * This iterates over all metadata, key_len and val_len are filled in
3831 * with the number of bytes put into the keys and values buffers.
3832 *
3833 * If the provided buffers are too short, the required lengths are filled
3834 * in and -ERANGE is returned. Otherwise, the buffers are filled with
3835 * the keys and values of the metadata, with a '\0' after each.
3836 *
3837 * @param io pool ioctx
3838 * @param app_name application name
3839 * @param keys buffer in which to store key names
3840 * @param key_len number of bytes in keys buffer
3841 * @param values buffer in which to store values
3842 * @param vals_len number of bytes in values buffer
3843 * @returns 0 on success, negative error code on failure
3844 * @returns -ERANGE if either buffer is too short
3845 */
3846 CEPH_RADOS_API int rados_application_metadata_list(rados_ioctx_t io,
3847 const char *app_name,
3848 char *keys, size_t *key_len,
3849 char *values,
3850 size_t *vals_len);
3851
3852 /**
3853 * @name Mon/OSD/PG Commands
3854 *
3855 * These interfaces send commands relating to the monitor, OSD, or PGs.
3856 *
3857 * @{
3858 */
3859
3860 /**
3861 * Send monitor command.
3862 *
3863 * @note Takes command string in carefully-formatted JSON; must match
3864 * defined commands, types, etc.
3865 *
3866 * The result buffers are allocated on the heap; the caller is
3867 * expected to release that memory with rados_buffer_free(). The
3868 * buffer and length pointers can all be NULL, in which case they are
3869 * not filled in.
3870 *
3871 * @param cluster cluster handle
3872 * @param cmd an array of char *'s representing the command
3873 * @param cmdlen count of valid entries in cmd
3874 * @param inbuf any bulk input data (crush map, etc.)
3875 * @param inbuflen input buffer length
3876 * @param outbuf double pointer to output buffer
3877 * @param outbuflen pointer to output buffer length
3878 * @param outs double pointer to status string
3879 * @param outslen pointer to status string length
3880 * @returns 0 on success, negative error code on failure
3881 */
3882 CEPH_RADOS_API int rados_mon_command(rados_t cluster, const char **cmd,
3883 size_t cmdlen, const char *inbuf,
3884 size_t inbuflen, char **outbuf,
3885 size_t *outbuflen, char **outs,
3886 size_t *outslen);
3887
3888 /**
3889 * Send ceph-mgr command.
3890 *
3891 * @note Takes command string in carefully-formatted JSON; must match
3892 * defined commands, types, etc.
3893 *
3894 * The result buffers are allocated on the heap; the caller is
3895 * expected to release that memory with rados_buffer_free(). The
3896 * buffer and length pointers can all be NULL, in which case they are
3897 * not filled in.
3898 *
3899 * @param cluster cluster handle
3900 * @param cmd an array of char *'s representing the command
3901 * @param cmdlen count of valid entries in cmd
3902 * @param inbuf any bulk input data (crush map, etc.)
3903 * @param inbuflen input buffer length
3904 * @param outbuf double pointer to output buffer
3905 * @param outbuflen pointer to output buffer length
3906 * @param outs double pointer to status string
3907 * @param outslen pointer to status string length
3908 * @returns 0 on success, negative error code on failure
3909 */
3910 CEPH_RADOS_API int rados_mgr_command(rados_t cluster, const char **cmd,
3911 size_t cmdlen, const char *inbuf,
3912 size_t inbuflen, char **outbuf,
3913 size_t *outbuflen, char **outs,
3914 size_t *outslen);
3915
3916 /**
3917 * Send ceph-mgr tell command.
3918 *
3919 * @note Takes command string in carefully-formatted JSON; must match
3920 * defined commands, types, etc.
3921 *
3922 * The result buffers are allocated on the heap; the caller is
3923 * expected to release that memory with rados_buffer_free(). The
3924 * buffer and length pointers can all be NULL, in which case they are
3925 * not filled in.
3926 *
3927 * @param cluster cluster handle
3928 * @param name mgr name to target
3929 * @param cmd an array of char *'s representing the command
3930 * @param cmdlen count of valid entries in cmd
3931 * @param inbuf any bulk input data (crush map, etc.)
3932 * @param inbuflen input buffer length
3933 * @param outbuf double pointer to output buffer
3934 * @param outbuflen pointer to output buffer length
3935 * @param outs double pointer to status string
3936 * @param outslen pointer to status string length
3937 * @returns 0 on success, negative error code on failure
3938 */
3939 CEPH_RADOS_API int rados_mgr_command_target(
3940 rados_t cluster,
3941 const char *name,
3942 const char **cmd,
3943 size_t cmdlen, const char *inbuf,
3944 size_t inbuflen, char **outbuf,
3945 size_t *outbuflen, char **outs,
3946 size_t *outslen);
3947
3948 /**
3949 * Send monitor command to a specific monitor.
3950 *
3951 * @note Takes command string in carefully-formatted JSON; must match
3952 * defined commands, types, etc.
3953 *
3954 * The result buffers are allocated on the heap; the caller is
3955 * expected to release that memory with rados_buffer_free(). The
3956 * buffer and length pointers can all be NULL, in which case they are
3957 * not filled in.
3958 *
3959 * @param cluster cluster handle
3960 * @param name target monitor's name
3961 * @param cmd an array of char *'s representing the command
3962 * @param cmdlen count of valid entries in cmd
3963 * @param inbuf any bulk input data (crush map, etc.)
3964 * @param inbuflen input buffer length
3965 * @param outbuf double pointer to output buffer
3966 * @param outbuflen pointer to output buffer length
3967 * @param outs double pointer to status string
3968 * @param outslen pointer to status string length
3969 * @returns 0 on success, negative error code on failure
3970 */
3971 CEPH_RADOS_API int rados_mon_command_target(rados_t cluster, const char *name,
3972 const char **cmd, size_t cmdlen,
3973 const char *inbuf, size_t inbuflen,
3974 char **outbuf, size_t *outbuflen,
3975 char **outs, size_t *outslen);
3976
3977 /**
3978 * free a rados-allocated buffer
3979 *
3980 * Release memory allocated by librados calls like rados_mon_command().
3981 *
3982 * @param buf buffer pointer
3983 */
3984 CEPH_RADOS_API void rados_buffer_free(char *buf);
3985
3986 CEPH_RADOS_API int rados_osd_command(rados_t cluster, int osdid,
3987 const char **cmd, size_t cmdlen,
3988 const char *inbuf, size_t inbuflen,
3989 char **outbuf, size_t *outbuflen,
3990 char **outs, size_t *outslen);
3991
3992 CEPH_RADOS_API int rados_pg_command(rados_t cluster, const char *pgstr,
3993 const char **cmd, size_t cmdlen,
3994 const char *inbuf, size_t inbuflen,
3995 char **outbuf, size_t *outbuflen,
3996 char **outs, size_t *outslen);
3997
3998 CEPH_RADOS_API int rados_mgr_command(rados_t cluster,
3999 const char **cmd, size_t cmdlen,
4000 const char *inbuf, size_t inbuflen,
4001 char **outbuf, size_t *outbuflen,
4002 char **outs, size_t *outslen);
4003
4004 /*
4005 * This is not a doxygen comment leadin, because doxygen breaks on
4006 * a typedef with function params and returns, and I can't figure out
4007 * how to fix it.
4008 *
4009 * Monitor cluster log
4010 *
4011 * Monitor events logged to the cluster log. The callback get each
4012 * log entry both as a single formatted line and with each field in a
4013 * separate arg.
4014 *
4015 * Calling with a cb argument of NULL will deregister any previously
4016 * registered callback.
4017 *
4018 * @param cluster cluster handle
4019 * @param level minimum log level (debug, info, warn|warning, err|error)
4020 * @param cb callback to run for each log message. It MUST NOT block
4021 * nor call back into librados.
4022 * @param arg void argument to pass to cb
4023 *
4024 * @returns 0 on success, negative code on error
4025 */
4026 typedef void (*rados_log_callback_t)(void *arg,
4027 const char *line,
4028 const char *who,
4029 uint64_t sec, uint64_t nsec,
4030 uint64_t seq, const char *level,
4031 const char *msg);
4032
4033 /*
4034 * This is not a doxygen comment leadin, because doxygen breaks on
4035 * a typedef with function params and returns, and I can't figure out
4036 * how to fix it.
4037 *
4038 * Monitor cluster log
4039 *
4040 * Monitor events logged to the cluster log. The callback get each
4041 * log entry both as a single formatted line and with each field in a
4042 * separate arg.
4043 *
4044 * Calling with a cb argument of NULL will deregister any previously
4045 * registered callback.
4046 *
4047 * @param cluster cluster handle
4048 * @param level minimum log level (debug, info, warn|warning, err|error)
4049 * @param cb callback to run for each log message. It MUST NOT block
4050 * nor call back into librados.
4051 * @param arg void argument to pass to cb
4052 *
4053 * @returns 0 on success, negative code on error
4054 */
4055 typedef void (*rados_log_callback2_t)(void *arg,
4056 const char *line,
4057 const char *channel,
4058 const char *who,
4059 const char *name,
4060 uint64_t sec, uint64_t nsec,
4061 uint64_t seq, const char *level,
4062 const char *msg);
4063
4064 CEPH_RADOS_API int rados_monitor_log(rados_t cluster, const char *level,
4065 rados_log_callback_t cb, void *arg);
4066 CEPH_RADOS_API int rados_monitor_log2(rados_t cluster, const char *level,
4067 rados_log_callback2_t cb, void *arg);
4068
4069
4070 /**
4071 * register daemon instance for a service
4072 *
4073 * Register us as a daemon providing a particular service. We identify
4074 * the service (e.g., 'rgw') and our instance name (e.g., 'rgw.$hostname').
4075 * The metadata is a map of keys and values with arbitrary static metdata
4076 * for this instance. The encoding is a series of NULL-terminated strings,
4077 * alternating key names and values, terminating with an empty key name.
4078 * For example, "foo\0bar\0this\0that\0\0" is the dict {foo=bar,this=that}.
4079 *
4080 * For the lifetime of the librados instance, regular beacons will be sent
4081 * to the cluster to maintain our registration in the service map.
4082 *
4083 * @param cluster handle
4084 * @param service service name
4085 * @param daemon daemon instance name
4086 * @param metadata_dict static daemon metadata dict
4087 */
4088 CEPH_RADOS_API int rados_service_register(
4089 rados_t cluster,
4090 const char *service,
4091 const char *daemon,
4092 const char *metadata_dict);
4093
4094 /**
4095 * update daemon status
4096 *
4097 * Update our mutable status information in the service map.
4098 *
4099 * The status dict is encoded the same way the daemon metadata is encoded
4100 * for rados_service_register. For example, "foo\0bar\0this\0that\0\0" is
4101 * {foo=bar,this=that}.
4102 *
4103 * @param cluster rados cluster handle
4104 * @param status_dict status dict
4105 */
4106 CEPH_RADOS_API int rados_service_update_status(
4107 rados_t cluster,
4108 const char *status_dict);
4109
4110 /** @} Mon/OSD/PG commands */
4111
4112 /*
4113 * These methods are no longer supported and return -ENOTSUP where possible.
4114 */
4115 CEPH_RADOS_API int rados_objects_list_open(
4116 rados_ioctx_t io,
4117 rados_list_ctx_t *ctx) __attribute__((deprecated));
4118 CEPH_RADOS_API uint32_t rados_objects_list_get_pg_hash_position(
4119 rados_list_ctx_t ctx) __attribute__((deprecated));
4120 CEPH_RADOS_API uint32_t rados_objects_list_seek(
4121 rados_list_ctx_t ctx,
4122 uint32_t pos) __attribute__((deprecated));
4123 CEPH_RADOS_API int rados_objects_list_next(
4124 rados_list_ctx_t ctx,
4125 const char **entry,
4126 const char **key) __attribute__((deprecated));
4127 CEPH_RADOS_API void rados_objects_list_close(
4128 rados_list_ctx_t ctx) __attribute__((deprecated));
4129
4130
4131 #ifdef __cplusplus
4132 }
4133 #endif
4134
4135 #endif