-
Notifications
You must be signed in to change notification settings - Fork 6.1k
/
Copy pathlibrados.h
4156 lines (3847 loc) · 148 KB
/
librados.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2012 Sage Weil <sage@newdream.net>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef CEPH_LIBRADOS_H
#define CEPH_LIBRADOS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <netinet/in.h>
#if defined(__linux__)
#include <linux/types.h>
#elif defined(__FreeBSD__)
#include <sys/types.h>
#endif
#include <unistd.h>
#include <string.h>
#include "rados_types.h"
#include <sys/time.h>
#ifndef CEPH_OSD_TMAP_SET
/* These are also defined in rados.h and objclass.h. Keep them in sync! */
#define CEPH_OSD_TMAP_HDR 'h'
#define CEPH_OSD_TMAP_SET 's'
#define CEPH_OSD_TMAP_CREATE 'c'
#define CEPH_OSD_TMAP_RM 'r'
#endif
#define LIBRADOS_VER_MAJOR 3
#define LIBRADOS_VER_MINOR 0
#define LIBRADOS_VER_EXTRA 0
#define LIBRADOS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
#define LIBRADOS_VERSION_CODE LIBRADOS_VERSION(LIBRADOS_VER_MAJOR, LIBRADOS_VER_MINOR, LIBRADOS_VER_EXTRA)
#define LIBRADOS_SUPPORTS_WATCH 1
#define LIBRADOS_SUPPORTS_SERVICES 1
#define LIBRADOS_SUPPORTS_GETADDRS 1
#define LIBRADOS_SUPPORTS_APP_METADATA 1
/* RADOS lock flags
* They are also defined in cls_lock_types.h. Keep them in sync!
*/
#define LIBRADOS_LOCK_FLAG_RENEW (1u<<0)
#define LIBRADOS_LOCK_FLAG_MAY_RENEW LIBRADOS_LOCK_FLAG_RENEW
#define LIBRADOS_LOCK_FLAG_MUST_RENEW (1u<<1)
/*
* Constants for rados_write_op_create().
*/
#define LIBRADOS_CREATE_EXCLUSIVE 1
#define LIBRADOS_CREATE_IDEMPOTENT 0
/*
* Flags that can be set on a per-op basis via
* rados_read_op_set_flags() and rados_write_op_set_flags().
*/
enum {
// fail a create operation if the object already exists
LIBRADOS_OP_FLAG_EXCL = 0x1,
// allow the transaction to succeed even if the flagged op fails
LIBRADOS_OP_FLAG_FAILOK = 0x2,
// indicate read/write op random
LIBRADOS_OP_FLAG_FADVISE_RANDOM = 0x4,
// indicate read/write op sequential
LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL = 0x8,
// indicate read/write data will be accessed in the near future (by someone)
LIBRADOS_OP_FLAG_FADVISE_WILLNEED = 0x10,
// indicate read/write data will not accessed in the near future (by anyone)
LIBRADOS_OP_FLAG_FADVISE_DONTNEED = 0x20,
// indicate read/write data will not accessed again (by *this* client)
LIBRADOS_OP_FLAG_FADVISE_NOCACHE = 0x40,
// optionally support FUA (force unit access) on write requests
LIBRADOS_OP_FLAG_FADVISE_FUA = 0x80,
};
#define CEPH_RADOS_API
/**
* @name xattr comparison operations
* Operators for comparing xattrs on objects, and aborting the
* rados_read_op or rados_write_op transaction if the comparison
* fails.
*
* @{
*/
enum {
LIBRADOS_CMPXATTR_OP_EQ = 1,
LIBRADOS_CMPXATTR_OP_NE = 2,
LIBRADOS_CMPXATTR_OP_GT = 3,
LIBRADOS_CMPXATTR_OP_GTE = 4,
LIBRADOS_CMPXATTR_OP_LT = 5,
LIBRADOS_CMPXATTR_OP_LTE = 6
};
/** @} */
/**
* @name Operation Flags
* Flags for rados_read_op_operate(), rados_write_op_operate(),
* rados_aio_read_op_operate(), and rados_aio_write_op_operate().
* See librados.hpp for details.
* @{
*/
enum {
LIBRADOS_OPERATION_NOFLAG = 0,
LIBRADOS_OPERATION_BALANCE_READS = 1,
LIBRADOS_OPERATION_LOCALIZE_READS = 2,
LIBRADOS_OPERATION_ORDER_READS_WRITES = 4,
LIBRADOS_OPERATION_IGNORE_CACHE = 8,
LIBRADOS_OPERATION_SKIPRWLOCKS = 16,
LIBRADOS_OPERATION_IGNORE_OVERLAY = 32,
/* send requests to cluster despite the cluster or pool being marked
full; ops will either succeed (e.g., delete) or return EDQUOT or
ENOSPC. */
LIBRADOS_OPERATION_FULL_TRY = 64,
/*
* Mainly for delete op
*/
LIBRADOS_OPERATION_FULL_FORCE = 128,
LIBRADOS_OPERATION_IGNORE_REDIRECT = 256,
LIBRADOS_OPERATION_ORDERSNAP = 512,
/* enable/allow >0 return values and payloads on write/update */
LIBRADOS_OPERATION_RETURNVEC = 1024,
};
/** @} */
/**
* @name Alloc hint flags
* Flags for rados_write_op_alloc_hint2() and rados_set_alloc_hint2()
* indicating future IO patterns.
* @{
*/
enum {
LIBRADOS_ALLOC_HINT_FLAG_SEQUENTIAL_WRITE = 1,
LIBRADOS_ALLOC_HINT_FLAG_RANDOM_WRITE = 2,
LIBRADOS_ALLOC_HINT_FLAG_SEQUENTIAL_READ = 4,
LIBRADOS_ALLOC_HINT_FLAG_RANDOM_READ = 8,
LIBRADOS_ALLOC_HINT_FLAG_APPEND_ONLY = 16,
LIBRADOS_ALLOC_HINT_FLAG_IMMUTABLE = 32,
LIBRADOS_ALLOC_HINT_FLAG_SHORTLIVED = 64,
LIBRADOS_ALLOC_HINT_FLAG_LONGLIVED = 128,
LIBRADOS_ALLOC_HINT_FLAG_COMPRESSIBLE = 256,
LIBRADOS_ALLOC_HINT_FLAG_INCOMPRESSIBLE = 512,
};
/** @} */
typedef enum {
LIBRADOS_CHECKSUM_TYPE_XXHASH32 = 0,
LIBRADOS_CHECKSUM_TYPE_XXHASH64 = 1,
LIBRADOS_CHECKSUM_TYPE_CRC32C = 2
} rados_checksum_type_t;
/*
* snap id contants
*/
#define LIBRADOS_SNAP_HEAD UINT64_C(-2)
#define LIBRADOS_SNAP_DIR UINT64_C(-1)
/**
* @typedef rados_t
*
* A handle for interacting with a RADOS cluster. It encapsulates all
* RADOS client configuration, including username, key for
* authentication, logging, and debugging. Talking to different clusters
* -- or to the same cluster with different users -- requires
* different cluster handles.
*/
#ifndef VOIDPTR_RADOS_T
#define VOIDPTR_RADOS_T
typedef void *rados_t;
#endif //VOIDPTR_RADOS_T
/**
* @typedef rados_config_t
*
* A handle for the ceph configuration context for the rados_t cluster
* instance. This can be used to share configuration context/state
* (e.g., logging configuration) between librados instance.
*
* @warning The config context does not have independent reference
* counting. As such, a rados_config_t handle retrieved from a given
* rados_t is only valid as long as that rados_t.
*/
typedef void *rados_config_t;
/**
* @typedef rados_ioctx_t
*
* An io context encapsulates a few settings for all I/O operations
* done on it:
* - pool - set when the io context is created (see rados_ioctx_create())
* - snapshot context for writes (see
* rados_ioctx_selfmanaged_snap_set_write_ctx())
* - snapshot id to read from (see rados_ioctx_snap_set_read())
* - object locator for all single-object operations (see
* rados_ioctx_locator_set_key())
* - namespace for all single-object operations (see
* rados_ioctx_set_namespace()). Set to LIBRADOS_ALL_NSPACES
* before rados_nobjects_list_open() will list all objects in all
* namespaces.
*
* @warning Changing any of these settings is not thread-safe -
* librados users must synchronize any of these changes on their own,
* or use separate io contexts for each thread
*/
typedef void *rados_ioctx_t;
/**
* @typedef rados_list_ctx_t
*
* An iterator for listing the objects in a pool.
* Used with rados_nobjects_list_open(),
* rados_nobjects_list_next(), rados_nobjects_list_next2(), and
* rados_nobjects_list_close().
*/
typedef void *rados_list_ctx_t;
/**
* @typedef rados_object_list_cursor
*
* The cursor used with rados_enumerate_objects
* and accompanying methods.
*/
typedef void * rados_object_list_cursor;
/**
* @struct rados_object_list_item
*
* The item populated by rados_object_list in
* the results array.
*/
typedef struct {
/// oid length
size_t oid_length;
/// name of the object
char *oid;
/// namespace length
size_t nspace_length;
/// the object namespace
char *nspace;
/// locator length
size_t locator_length;
/// object locator
char *locator;
} rados_object_list_item;
/**
* @typedef rados_snap_t
* The id of a snapshot.
*/
typedef uint64_t rados_snap_t;
/**
* @typedef rados_xattrs_iter_t
* An iterator for listing extended attrbutes on an object.
* Used with rados_getxattrs(), rados_getxattrs_next(), and
* rados_getxattrs_end().
*/
typedef void *rados_xattrs_iter_t;
/**
* @typedef rados_omap_iter_t
* An iterator for listing omap key/value pairs on an object.
* Used with rados_read_op_omap_get_keys(), rados_read_op_omap_get_vals(),
* rados_read_op_omap_get_vals_by_keys(), rados_omap_get_next(), and
* rados_omap_get_end().
*/
typedef void *rados_omap_iter_t;
/**
* @struct rados_pool_stat_t
* Usage information for a pool.
*/
struct rados_pool_stat_t {
/// space used in bytes
uint64_t num_bytes;
/// space used in KB
uint64_t num_kb;
/// number of objects in the pool
uint64_t num_objects;
/// number of clones of objects
uint64_t num_object_clones;
/// num_objects * num_replicas
uint64_t num_object_copies;
/// number of objects missing on primary
uint64_t num_objects_missing_on_primary;
/// number of objects found on no OSDs
uint64_t num_objects_unfound;
/// number of objects replicated fewer times than they should be
/// (but found on at least one OSD)
uint64_t num_objects_degraded;
/// number of objects read
uint64_t num_rd;
/// objects read in KB
uint64_t num_rd_kb;
/// number of objects written
uint64_t num_wr;
/// objects written in KB
uint64_t num_wr_kb;
/// bytes originally provided by user
uint64_t num_user_bytes;
/// bytes passed compression
uint64_t compressed_bytes_orig;
/// bytes resulted after compression
uint64_t compressed_bytes;
/// bytes allocated at storage
uint64_t compressed_bytes_alloc;
};
/**
* @struct rados_cluster_stat_t
* Cluster-wide usage information
*/
struct rados_cluster_stat_t {
/// total device size
uint64_t kb;
/// total used
uint64_t kb_used;
/// total available/free
uint64_t kb_avail;
/// number of objects
uint64_t num_objects;
};
/**
* @typedef rados_write_op_t
*
* An object write operation stores a number of operations which can be
* executed atomically. For usage, see:
* - Creation and deletion: rados_create_write_op() rados_release_write_op()
* - Extended attribute manipulation: rados_write_op_cmpxattr()
* rados_write_op_cmpxattr(), rados_write_op_setxattr(),
* rados_write_op_rmxattr()
* - Object map key/value pairs: rados_write_op_omap_set(),
* rados_write_op_omap_rm_keys(), rados_write_op_omap_clear(),
* rados_write_op_omap_cmp()
* - Object properties: rados_write_op_assert_exists(),
* rados_write_op_assert_version()
* - Creating objects: rados_write_op_create()
* - IO on objects: rados_write_op_append(), rados_write_op_write(), rados_write_op_zero
* rados_write_op_write_full(), rados_write_op_writesame(), rados_write_op_remove,
* rados_write_op_truncate(), rados_write_op_zero(), rados_write_op_cmpext()
* - Hints: rados_write_op_set_alloc_hint()
* - Performing the operation: rados_write_op_operate(), rados_aio_write_op_operate()
*/
typedef void *rados_write_op_t;
/**
* @typedef rados_read_op_t
*
* An object read operation stores a number of operations which can be
* executed atomically. For usage, see:
* - Creation and deletion: rados_create_read_op() rados_release_read_op()
* - Extended attribute manipulation: rados_read_op_cmpxattr(),
* rados_read_op_getxattr(), rados_read_op_getxattrs()
* - Object map key/value pairs: rados_read_op_omap_get_vals(),
* rados_read_op_omap_get_keys(), rados_read_op_omap_get_vals_by_keys(),
* rados_read_op_omap_cmp()
* - Object properties: rados_read_op_stat(), rados_read_op_assert_exists(),
* rados_read_op_assert_version()
* - IO on objects: rados_read_op_read(), rados_read_op_checksum(),
* rados_read_op_cmpext()
* - Custom operations: rados_read_op_exec(), rados_read_op_exec_user_buf()
* - Request properties: rados_read_op_set_flags()
* - Performing the operation: rados_read_op_operate(),
* rados_aio_read_op_operate()
*/
typedef void *rados_read_op_t;
/**
* @typedef rados_completion_t
* Represents the state of an asynchronous operation - it contains the
* return value once the operation completes, and can be used to block
* until the operation is complete or safe.
*/
typedef void *rados_completion_t;
/**
* @struct blkin_trace_info
* blkin trace information for Zipkin tracing
*/
struct blkin_trace_info;
/**
* Get the version of librados.
*
* The version number is major.minor.extra. Note that this is
* unrelated to the Ceph version number.
*
* TODO: define version semantics, i.e.:
* - incrementing major is for backwards-incompatible changes
* - incrementing minor is for backwards-compatible changes
* - incrementing extra is for bug fixes
*
* @param major where to store the major version number
* @param minor where to store the minor version number
* @param extra where to store the extra version number
*/
CEPH_RADOS_API void rados_version(int *major, int *minor, int *extra);
/**
* @name Setup and Teardown
* These are the first and last functions to that should be called
* when using librados.
*
* @{
*/
/**
* Create a handle for communicating with a RADOS cluster.
*
* Ceph environment variables are read when this is called, so if
* $CEPH_ARGS specifies everything you need to connect, no further
* configuration is necessary.
*
* @param cluster where to store the handle
* @param id the user to connect as (i.e. admin, not client.admin)
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_create(rados_t *cluster, const char * const id);
/**
* Extended version of rados_create.
*
* Like rados_create, but
* 1) don't assume 'client\.'+id; allow full specification of name
* 2) allow specification of cluster name
* 3) flags for future expansion
*/
CEPH_RADOS_API int rados_create2(rados_t *pcluster,
const char *const clustername,
const char * const name, uint64_t flags);
/**
* Initialize a cluster handle from an existing configuration.
*
* Share configuration state with another rados_t instance.
*
* @param cluster where to store the handle
* @param cct the existing configuration to use
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_create_with_context(rados_t *cluster,
rados_config_t cct);
/**
* Ping the monitor with ID mon_id, storing the resulting reply in
* buf (if specified) with a maximum size of len.
*
* The result buffer is allocated on the heap; the caller is
* expected to release that memory with rados_buffer_free(). The
* buffer and length pointers can be NULL, in which case they are
* not filled in.
*
* @param cluster cluster handle
* @param mon_id [in] ID of the monitor to ping
* @param outstr [out] double pointer with the resulting reply
* @param outstrlen [out] pointer with the size of the reply in outstr
*/
CEPH_RADOS_API int rados_ping_monitor(rados_t cluster, const char *mon_id,
char **outstr, size_t *outstrlen);
/**
* Connect to the cluster.
*
* @note BUG: Before calling this, calling a function that communicates with the
* cluster will crash.
*
* @pre The cluster handle is configured with at least a monitor
* address. If cephx is enabled, a client name and secret must also be
* set.
*
* @post If this succeeds, any function in librados may be used
*
* @param cluster The cluster to connect to.
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_connect(rados_t cluster);
/**
* Disconnects from the cluster.
*
* For clean up, this is only necessary after rados_connect() has
* succeeded.
*
* @warning This does not guarantee any asynchronous writes have
* completed. To do that, you must call rados_aio_flush() on all open
* io contexts.
*
* @warning We implicitly call rados_watch_flush() on shutdown. If
* there are watches being used, this should be done explicitly before
* destroying the relevant IoCtx. We do it here as a safety measure.
*
* @post the cluster handle cannot be used again
*
* @param cluster the cluster to shutdown
*/
CEPH_RADOS_API void rados_shutdown(rados_t cluster);
/** @} init */
/**
* @name Configuration
* These functions read and update Ceph configuration for a cluster
* handle. Any configuration changes must be done before connecting to
* the cluster.
*
* Options that librados users might want to set include:
* - mon_host
* - auth_supported
* - key, keyfile, or keyring when using cephx
* - log_file, log_to_stderr, err_to_stderr, and log_to_syslog
* - debug_rados, debug_objecter, debug_monc, debug_auth, or debug_ms
*
* See docs.ceph.com for information about available configuration options`
*
* @{
*/
/**
* Configure the cluster handle using a Ceph config file
*
* If path is NULL, the default locations are searched, and the first
* found is used. The locations are:
* - $CEPH_CONF (environment variable)
* - /etc/ceph/ceph.conf
* - ~/.ceph/config
* - ceph.conf (in the current working directory)
*
* @pre rados_connect() has not been called on the cluster handle
*
* @param cluster cluster handle to configure
* @param path path to a Ceph configuration file
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_conf_read_file(rados_t cluster, const char *path);
/**
* Configure the cluster handle with command line arguments
*
* argv can contain any common Ceph command line option, including any
* configuration parameter prefixed by '--' and replacing spaces with
* dashes or underscores. For example, the following options are equivalent:
* - --mon-host 10.0.0.1:6789
* - --mon_host 10.0.0.1:6789
* - -m 10.0.0.1:6789
*
* @pre rados_connect() has not been called on the cluster handle
*
* @param cluster cluster handle to configure
* @param argc number of arguments in argv
* @param argv arguments to parse
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_conf_parse_argv(rados_t cluster, int argc,
const char **argv);
/**
* Configure the cluster handle with command line arguments, returning
* any remainders. Same rados_conf_parse_argv, except for extra
* remargv argument to hold returns unrecognized arguments.
*
* @pre rados_connect() has not been called on the cluster handle
*
* @param cluster cluster handle to configure
* @param argc number of arguments in argv
* @param argv arguments to parse
* @param remargv char* array for returned unrecognized arguments
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_conf_parse_argv_remainder(rados_t cluster, int argc,
const char **argv,
const char **remargv);
/**
* Configure the cluster handle based on an environment variable
*
* The contents of the environment variable are parsed as if they were
* Ceph command line options. If var is NULL, the CEPH_ARGS
* environment variable is used.
*
* @pre rados_connect() has not been called on the cluster handle
*
* @note BUG: this is not threadsafe - it uses a static buffer
*
* @param cluster cluster handle to configure
* @param var name of the environment variable to read
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_conf_parse_env(rados_t cluster, const char *var);
/**
* Set a configuration option
*
* @pre rados_connect() has not been called on the cluster handle
*
* @param cluster cluster handle to configure
* @param option option to set
* @param value value of the option
* @returns 0 on success, negative error code on failure
* @returns -ENOENT when the option is not a Ceph configuration option
*/
CEPH_RADOS_API int rados_conf_set(rados_t cluster, const char *option,
const char *value);
/**
* Get the value of a configuration option
*
* @param cluster configuration to read
* @param option which option to read
* @param buf where to write the configuration value
* @param len the size of buf in bytes
* @returns 0 on success, negative error code on failure
* @returns -ENAMETOOLONG if the buffer is too short to contain the
* requested value
*/
CEPH_RADOS_API int rados_conf_get(rados_t cluster, const char *option,
char *buf, size_t len);
/** @} config */
/**
* Read usage info about the cluster
*
* This tells you total space, space used, space available, and number
* of objects. These are not updated immediately when data is written,
* they are eventually consistent.
*
* @param cluster cluster to query
* @param result where to store the results
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_cluster_stat(rados_t cluster,
struct rados_cluster_stat_t *result);
/**
* Get the fsid of the cluster as a hexadecimal string.
*
* The fsid is a unique id of an entire Ceph cluster.
*
* @param cluster where to get the fsid
* @param buf where to write the fsid
* @param len the size of buf in bytes (should be 37)
* @returns 0 on success, negative error code on failure
* @returns -ERANGE if the buffer is too short to contain the
* fsid
*/
CEPH_RADOS_API int rados_cluster_fsid(rados_t cluster, char *buf, size_t len);
/**
* Get/wait for the most recent osdmap
*
* @param cluster the cluster to shutdown
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_wait_for_latest_osdmap(rados_t cluster);
/**
* @name Pools
*
* RADOS pools are separate namespaces for objects. Pools may have
* different crush rules associated with them, so they could have
* differing replication levels or placement strategies. RADOS
* permissions are also tied to pools - users can have different read,
* write, and execute permissions on a per-pool basis.
*
* @{
*/
/**
* List pools
*
* Gets a list of pool names as NULL-terminated strings. The pool
* names will be placed in the supplied buffer one after another.
* After the last pool name, there will be two 0 bytes in a row.
*
* If len is too short to fit all the pool name entries we need, we will fill
* as much as we can.
*
* Buf may be null to determine the buffer size needed to list all pools.
*
* @param cluster cluster handle
* @param buf output buffer
* @param len output buffer length
* @returns length of the buffer we would need to list all pools
*/
CEPH_RADOS_API int rados_pool_list(rados_t cluster, char *buf, size_t len);
/**
* List inconsistent placement groups of the given pool
*
* Gets a list of inconsistent placement groups as NULL-terminated strings.
* The placement group names will be placed in the supplied buffer one after
* another. After the last name, there will be two 0 types in a row.
*
* If len is too short to fit all the placement group entries we need, we will
* fill as much as we can.
*
* @param cluster cluster handle
* @param pool pool ID
* @param buf output buffer
* @param len output buffer length
* @returns length of the buffer we would need to list all pools
*/
CEPH_RADOS_API int rados_inconsistent_pg_list(rados_t cluster, int64_t pool,
char *buf, size_t len);
/**
* Get a configuration handle for a rados cluster handle
*
* This handle is valid only as long as the cluster handle is valid.
*
* @param cluster cluster handle
* @returns config handle for this cluster
*/
CEPH_RADOS_API rados_config_t rados_cct(rados_t cluster);
/**
* Get a global id for current instance
*
* This id is a unique representation of current connection to the cluster
*
* @param cluster cluster handle
* @returns instance global id
*/
CEPH_RADOS_API uint64_t rados_get_instance_id(rados_t cluster);
/**
* Gets the minimum compatible OSD version
*
* @param cluster cluster handle
* @param require_osd_release [out] minimum compatible OSD version
* based upon the current features
* @returns 0 on sucess, negative error code on failure
*/
CEPH_RADOS_API int rados_get_min_compatible_osd(rados_t cluster,
int8_t* require_osd_release);
/**
* Gets the minimum compatible client version
*
* @param cluster cluster handle
* @param min_compat_client [out] minimum compatible client version
* based upon the current features
* @param require_min_compat_client [out] required minimum client version
* based upon explicit setting
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_get_min_compatible_client(rados_t cluster,
int8_t* min_compat_client,
int8_t* require_min_compat_client);
/**
* Create an io context
*
* The io context allows you to perform operations within a particular
* pool. For more details see rados_ioctx_t.
*
* @param cluster which cluster the pool is in
* @param pool_name name of the pool
* @param ioctx where to store the io context
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_ioctx_create(rados_t cluster, const char *pool_name,
rados_ioctx_t *ioctx);
CEPH_RADOS_API int rados_ioctx_create2(rados_t cluster, int64_t pool_id,
rados_ioctx_t *ioctx);
/**
* The opposite of rados_ioctx_create
*
* This just tells librados that you no longer need to use the io context.
* It may not be freed immediately if there are pending asynchronous
* requests on it, but you should not use an io context again after
* calling this function on it.
*
* @warning This does not guarantee any asynchronous
* writes have completed. You must call rados_aio_flush()
* on the io context before destroying it to do that.
*
* @warning If this ioctx is used by rados_watch, the caller needs to
* be sure that all registered watches are disconnected via
* rados_unwatch() and that rados_watch_flush() is called. This
* ensures that a racing watch callback does not make use of a
* destroyed ioctx.
*
* @param io the io context to dispose of
*/
CEPH_RADOS_API void rados_ioctx_destroy(rados_ioctx_t io);
/**
* Get configuration handle for a pool handle
*
* @param io pool handle
* @returns rados_config_t for this cluster
*/
CEPH_RADOS_API rados_config_t rados_ioctx_cct(rados_ioctx_t io);
/**
* Get the cluster handle used by this rados_ioctx_t
* Note that this is a weak reference, and should not
* be destroyed via rados_shutdown().
*
* @param io the io context
* @returns the cluster handle for this io context
*/
CEPH_RADOS_API rados_t rados_ioctx_get_cluster(rados_ioctx_t io);
/**
* Get pool usage statistics
*
* Fills in a rados_pool_stat_t after querying the cluster.
*
* @param io determines which pool to query
* @param stats where to store the results
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_ioctx_pool_stat(rados_ioctx_t io,
struct rados_pool_stat_t *stats);
/**
* Get the id of a pool
*
* @param cluster which cluster the pool is in
* @param pool_name which pool to look up
* @returns id of the pool
* @returns -ENOENT if the pool is not found
*/
CEPH_RADOS_API int64_t rados_pool_lookup(rados_t cluster,
const char *pool_name);
/**
* Get the name of a pool
*
* @param cluster which cluster the pool is in
* @param id the id of the pool
* @param buf where to store the pool name
* @param maxlen size of buffer where name will be stored
* @returns length of string stored, or -ERANGE if buffer too small
*/
CEPH_RADOS_API int rados_pool_reverse_lookup(rados_t cluster, int64_t id,
char *buf, size_t maxlen);
/**
* Create a pool with default settings
*
* The default crush rule is rule 0.
*
* @param cluster the cluster in which the pool will be created
* @param pool_name the name of the new pool
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_pool_create(rados_t cluster, const char *pool_name);
/**
* Create a pool owned by a specific auid.
*
* DEPRECATED: auid support has been removed, and this call will be removed in a future
* release.
*
* @param cluster the cluster in which the pool will be created
* @param pool_name the name of the new pool
* @param auid the id of the owner of the new pool
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_pool_create_with_auid(rados_t cluster,
const char *pool_name,
uint64_t auid)
__attribute__((deprecated));
/**
* Create a pool with a specific CRUSH rule
*
* @param cluster the cluster in which the pool will be created
* @param pool_name the name of the new pool
* @param crush_rule_num which rule to use for placement in the new pool1
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_pool_create_with_crush_rule(rados_t cluster,
const char *pool_name,
uint8_t crush_rule_num);
/**
* Create a pool with a specific CRUSH rule and auid
*
* DEPRECATED: auid support has been removed and this call will be removed
* in a future release.
*
* This is a combination of rados_pool_create_with_crush_rule() and
* rados_pool_create_with_auid().
*
* @param cluster the cluster in which the pool will be created
* @param pool_name the name of the new pool
* @param crush_rule_num which rule to use for placement in the new pool2
* @param auid the id of the owner of the new pool
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_pool_create_with_all(rados_t cluster,
const char *pool_name,
uint64_t auid,
uint8_t crush_rule_num)
__attribute__((deprecated));
/**
* Returns the pool that is the base tier for this pool.
*
* The return value is the ID of the pool that should be used to read from/write to.
* If tiering is not set up for the pool, returns \c pool.
*
* @param cluster the cluster the pool is in
* @param pool ID of the pool to query
* @param base_tier [out] base tier, or \c pool if tiering is not configured
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_pool_get_base_tier(rados_t cluster, int64_t pool,
int64_t* base_tier);
/**
* Delete a pool and all data inside it
*
* The pool is removed from the cluster immediately,
* but the actual data is deleted in the background.
*
* @param cluster the cluster the pool is in
* @param pool_name which pool to delete
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_pool_delete(rados_t cluster, const char *pool_name);
/**
* Attempt to change an io context's associated auid "owner"
*
* DEPRECATED: auid support has been removed and this call has no effect.
*
* Requires that you have write permission on both the current and new
* auid.
*
* @param io reference to the pool to change.
* @param auid the auid you wish the io to have.
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_ioctx_pool_set_auid(rados_ioctx_t io, uint64_t auid)
__attribute__((deprecated));
/**
* Get the auid of a pool
*
* DEPRECATED: auid support has been removed and this call always reports
* CEPH_AUTH_UID_DEFAULT (-1).
* @param io pool to query
* @param auid where to store the auid
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_ioctx_pool_get_auid(rados_ioctx_t io, uint64_t *auid)
__attribute__((deprecated));
/* deprecated, use rados_ioctx_pool_requires_alignment2 instead */
CEPH_RADOS_API int rados_ioctx_pool_requires_alignment(rados_ioctx_t io)
__attribute__((deprecated));
/**
* Test whether the specified pool requires alignment or not.
*
* @param io pool to query
* @param req 1 if alignment is supported, 0 if not.
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_ioctx_pool_requires_alignment2(rados_ioctx_t io,
int *req);
/* deprecated, use rados_ioctx_pool_required_alignment2 instead */
CEPH_RADOS_API uint64_t rados_ioctx_pool_required_alignment(rados_ioctx_t io)
__attribute__((deprecated));
/**
* Get the alignment flavor of a pool
*
* @param io pool to query
* @param alignment where to store the alignment flavor
* @returns 0 on success, negative error code on failure
*/
CEPH_RADOS_API int rados_ioctx_pool_required_alignment2(rados_ioctx_t io,
uint64_t *alignment);