summaryrefslogtreecommitdiffstats
path: root/src/include/rados/librados.h
blob: d9e39eceb1f9e96cfe5a984738f2cc0853409849 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
// -*- 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_t)(-2))
#define LIBRADOS_SNAP_DIR   ((uint64_t)(-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);

/**
 * Get the pool id of the io context
 *
 * @param io the io context to query
 * @returns the id of the pool the io context uses
 */
CEPH_RADOS_API int64_t rados_ioctx_get_id(rados_ioctx_t io);

/**
 * Get the pool name of the io context
 *
 * @param io the io context to query
 * @param buf pointer to buffer where name will be stored
 * @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_ioctx_get_pool_name(rados_ioctx_t io, char *buf,
                                             unsigned maxlen);

/** @} pools */

/**
 * @name Object Locators
 *
 * @{
 */

/**
 * Set the key for mapping objects to pgs within an io context.
 *
 * The key is used instead of the object name to determine which
 * placement groups an object is put in. This affects all subsequent
 * operations of the io context - until a different locator key is
 * set, all objects in this io context will be placed in the same pg.
 *
 * @param io the io context to change
 * @param key the key to use as the object locator, or NULL to discard
 * any previously set key
 */
CEPH_RADOS_API void rados_ioctx_locator_set_key(rados_ioctx_t io,
                                                const char *key);

/**
 * Set the namespace for objects within an io context
 *
 * The namespace specification further refines a pool into different
 * domains.  The mapping of objects to pgs is also based on this
 * value.
 *
 * @param io the io context to change
 * @param nspace the name to use as the namespace, or NULL use the
 * default namespace
 */
CEPH_RADOS_API void rados_ioctx_set_namespace(rados_ioctx_t io,
                                              const char *nspace);

/**
 * Get the namespace for objects within the io context
 *
 * @param io the io context to query
 * @param buf pointer to buffer where name will be stored
 * @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_ioctx_get_namespace(rados_ioctx_t io, char *buf,
                                             unsigned maxlen);

/** @} obj_loc */

/**
 * @name Listing Objects
 * @{
 */
/**
 * Start listing objects in a pool
 *
 * @param io the pool to list from
 * @param ctx the handle to store list context in
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_nobjects_list_open(rados_ioctx_t io,
                                            rados_list_ctx_t *ctx);

/**
 * Return hash position of iterator, rounded to the current PG
 *
 * @param ctx iterator marking where you are in the listing
 * @returns current hash position, rounded to the current pg
 */
CEPH_RADOS_API uint32_t rados_nobjects_list_get_pg_hash_position(rados_list_ctx_t ctx);

/**
 * Reposition object iterator to a different hash position
 *
 * @param ctx iterator marking where you are in the listing
 * @param pos hash position to move to
 * @returns actual (rounded) position we moved to
 */
CEPH_RADOS_API uint32_t rados_nobjects_list_seek(rados_list_ctx_t ctx,
                                                 uint32_t pos);

/**
 * Reposition object iterator to a different position
 *
 * @param ctx iterator marking where you are in the listing
 * @param cursor position to move to
 * @returns rounded position we moved to
 */
CEPH_RADOS_API uint32_t rados_nobjects_list_seek_cursor(rados_list_ctx_t ctx,
                                                        rados_object_list_cursor cursor);

/**
 * Reposition object iterator to a different position
 *
 * The returned handle must be released with rados_object_list_cursor_free().
 *
 * @param ctx iterator marking where you are in the listing
 * @param cursor where to store cursor
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_nobjects_list_get_cursor(rados_list_ctx_t ctx,
                                                  rados_object_list_cursor *cursor);

/**
 * Get the next object name and locator in the pool
 *
 * *entry and *key are valid until next call to rados_nobjects_list_*
 *
 * @param ctx iterator marking where you are in the listing
 * @param entry where to store the name of the entry
 * @param key where to store the object locator (set to NULL to ignore)
 * @param nspace where to store the object namespace (set to NULL to ignore)
 * @returns 0 on success, negative error code on failure
 * @returns -ENOENT when there are no more objects to list
 */
CEPH_RADOS_API int rados_nobjects_list_next(rados_list_ctx_t ctx,
                                            const char **entry,
	                                    const char **key,
                                            const char **nspace);

/**
 * Get the next object name, locator and their sizes in the pool
 *
 * The sizes allow to list objects with \0 (the NUL character)
 * in .e.g *entry. Is is unusual see such object names but a bug
 * in a client has risen the need to handle them as well.
 * *entry and *key are valid until next call to rados_nobjects_list_*
 *
 * @param ctx iterator marking where you are in the listing
 * @param entry where to store the name of the entry
 * @param key where to store the object locator (set to NULL to ignore)
 * @param nspace where to store the object namespace (set to NULL to ignore)
 * @param entry_size where to store the size of name of the entry
 * @param key_size where to store the size of object locator (set to NULL to ignore)
 * @param nspace_size where to store the size of object namespace (set to NULL to ignore)
 * @returns 0 on success, negative error code on failure
 * @returns -ENOENT when there are no more objects to list
 */
CEPH_RADOS_API int rados_nobjects_list_next2(rados_list_ctx_t ctx,
                                             const char **entry,
                                             const char **key,
                                             const char **nspace,
                                             size_t *entry_size,
                                             size_t *key_size,
                                             size_t *nspace_size);

/**
 * Close the object listing handle.
 *
 * This should be called when the handle is no longer needed.
 * The handle should not be used after it has been closed.
 *
 * @param ctx the handle to close
 */
CEPH_RADOS_API void rados_nobjects_list_close(rados_list_ctx_t ctx);

/**
 * Get cursor handle pointing to the *beginning* of a pool.
 *
 * This is an opaque handle pointing to the start of a pool.  It must
 * be released with rados_object_list_cursor_free().
 *
 * @param io ioctx for the pool
 * @returns handle for the pool, NULL on error (pool does not exist)
 */
CEPH_RADOS_API rados_object_list_cursor rados_object_list_begin(
  rados_ioctx_t io);

/**
 * Get cursor handle pointing to the *end* of a pool.
 *
 * This is an opaque handle pointing to the start of a pool.  It must
 * be released with rados_object_list_cursor_free().
 *
 * @param io ioctx for the pool
 * @returns handle for the pool, NULL on error (pool does not exist)
 */
CEPH_RADOS_API rados_object_list_cursor rados_object_list_end(rados_ioctx_t io);

/**
 * Check if a cursor has reached the end of a pool
 *
 * @param io ioctx
 * @param cur cursor
 * @returns 1 if the cursor has reached the end of the pool, 0 otherwise
 */
CEPH_RADOS_API int rados_object_list_is_end(rados_ioctx_t io,
    rados_object_list_cursor cur);

/**
 * Release a cursor
 *
 * Release a cursor.  The handle may not be used after this point.
 *
 * @param io ioctx
 * @param cur cursor
 */
CEPH_RADOS_API void rados_object_list_cursor_free(rados_ioctx_t io,
    rados_object_list_cursor cur);

/**
 * Compare two cursor positions
 *
 * Compare two cursors, and indicate whether the first cursor precedes,
 * matches, or follows the second.
 *
 * @param io ioctx
 * @param lhs first cursor
 * @param rhs second cursor
 * @returns -1, 0, or 1 for lhs < rhs, lhs == rhs, or lhs > rhs
 */
CEPH_RADOS_API int rados_object_list_cursor_cmp(rados_ioctx_t io,
    rados_object_list_cursor lhs, rados_object_list_cursor rhs);

/**
 * @return the number of items set in the results array
 */
CEPH_RADOS_API int rados_object_list(rados_ioctx_t io,
    const rados_object_list_cursor start,
    const rados_object_list_cursor finish,
    const size_t result_size,
    const char *filter_buf,
    const size_t filter_buf_len,
    rados_object_list_item *results,
    rados_object_list_cursor *next);

CEPH_RADOS_API void rados_object_list_free(
    const size_t result_size,
    rados_object_list_item *results);

/**
 * Obtain cursors delineating a subset of a range.  Use this
 * when you want to split up the work of iterating over the
 * global namespace.  Expected use case is when you are iterating
 * in parallel, with `m` workers, and each worker taking an id `n`.
 *
 * @param io ioctx
 * @param start start of the range to be sliced up (inclusive)
 * @param finish end of the range to be sliced up (exclusive)
 * @param n which of the m chunks you would like to get cursors for
 * @param m how many chunks to divide start-finish into
 * @param split_start cursor populated with start of the subrange (inclusive)
 * @param split_finish cursor populated with end of the subrange (exclusive)
 */
CEPH_RADOS_API void rados_object_list_slice(rados_ioctx_t io,
    const rados_object_list_cursor start,
    const rados_object_list_cursor finish,
    const size_t n,
    const size_t m,
    rados_object_list_cursor *split_start,
    rados_object_list_cursor *split_finish);


/** @} Listing Objects */

/**
 * @name Snapshots
 *
 * RADOS snapshots are based upon sequence numbers that form a
 * snapshot context. They are pool-specific. The snapshot context
 * consists of the current snapshot sequence number for a pool, and an
 * array of sequence numbers at which snapshots were taken, in
 * descending order. Whenever a snapshot is created or deleted, the
 * snapshot sequence number for the pool is increased. To add a new
 * snapshot, the new snapshot sequence number must be increased and
 * added to the snapshot context.
 *
 * There are two ways to manage these snapshot contexts:
 * -# within the RADOS cluster
 *    These are called pool snapshots, and store the snapshot context
 *    in the OSDMap. These represent a snapshot of all the objects in
 *    a pool.
 * -# within the RADOS clients
 *    These are called self-managed snapshots, and push the
 *    responsibility for keeping track of the snapshot context to the
 *    clients. For every write, the client must send the snapshot
 *    context. In librados, this is accomplished with
 *    rados_selfmanaged_snap_set_write_ctx(). These are more
 *    difficult to manage, but are restricted to specific objects
 *    instead of applying to an entire pool.
 *
 * @{
 */

/**
 * Create a pool-wide snapshot
 *
 * @param io the pool to snapshot
 * @param snapname the name of the snapshot
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_ioctx_snap_create(rados_ioctx_t io,
                                           const char *snapname);

/**
 * Delete a pool snapshot
 *
 * @param io the pool to delete the snapshot from
 * @param snapname which snapshot to delete
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_ioctx_snap_remove(rados_ioctx_t io,
                                           const char *snapname);

/**
 * Rollback an object to a pool snapshot
 *
 * The contents of the object will be the same as
 * when the snapshot was taken.
 *
 * @param io the pool in which the object is stored
 * @param oid the name of the object to rollback
 * @param snapname which snapshot to rollback to
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_ioctx_snap_rollback(rados_ioctx_t io, const char *oid,
		                             const char *snapname);

/**
 * @warning Deprecated: Use rados_ioctx_snap_rollback() instead
 */
CEPH_RADOS_API int rados_rollback(rados_ioctx_t io, const char *oid,
				  const char *snapname)
  __attribute__((deprecated));

/**
 * Set the snapshot from which reads are performed.
 *
 * Subsequent reads will return data as it was at the time of that
 * snapshot.
 *
 * @param io the io context to change
 * @param snap the id of the snapshot to set, or LIBRADOS_SNAP_HEAD for no
 * snapshot (i.e. normal operation)
 */
CEPH_RADOS_API void rados_ioctx_snap_set_read(rados_ioctx_t io,
                                              rados_snap_t snap);

/**
 * Allocate an ID for a self-managed snapshot
 *
 * Get a unique ID to put in the snaphot context to create a
 * snapshot. A clone of an object is not created until a write with
 * the new snapshot context is completed.
 *
 * @param io the pool in which the snapshot will exist
 * @param snapid where to store the newly allocated snapshot ID
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_ioctx_selfmanaged_snap_create(rados_ioctx_t io,
                                                       rados_snap_t *snapid);
CEPH_RADOS_API void
rados_aio_ioctx_selfmanaged_snap_create(rados_ioctx_t io,
                                        rados_snap_t *snapid,
                                        rados_completion_t completion);

/**
 * Remove a self-managed snapshot
 *
 * This increases the snapshot sequence number, which will cause
 * snapshots to be removed lazily.
 *
 * @param io the pool in which the snapshot will exist
 * @param snapid where to store the newly allocated snapshot ID
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_ioctx_selfmanaged_snap_remove(rados_ioctx_t io,
                                                       rados_snap_t snapid);
CEPH_RADOS_API void
rados_aio_ioctx_selfmanaged_snap_remove(rados_ioctx_t io,
                                        rados_snap_t snapid,
                                        rados_completion_t completion);

/**
 * Rollback an object to a self-managed snapshot
 *
 * The contents of the object will be the same as
 * when the snapshot was taken.
 *
 * @param io the pool in which the object is stored
 * @param oid the name of the object to rollback
 * @param snapid which snapshot to rollback to
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_ioctx_selfmanaged_snap_rollback(rados_ioctx_t io,
                                                         const char *oid,
                                                         rados_snap_t snapid);

/**
 * Set the snapshot context for use when writing to objects
 *
 * This is stored in the io context, and applies to all future writes.
 *
 * @param io the io context to change
 * @param seq the newest snapshot sequence number for the pool
 * @param snaps array of snapshots in sorted by descending id
 * @param num_snaps how many snaphosts are in the snaps array
 * @returns 0 on success, negative error code on failure
 * @returns -EINVAL if snaps are not in descending order
 */
CEPH_RADOS_API int rados_ioctx_selfmanaged_snap_set_write_ctx(rados_ioctx_t io,
                                                              rados_snap_t seq,
                                                              rados_snap_t *snaps,
                                                              int num_snaps);

/**
 * List all the ids of pool snapshots
 *
 * If the output array does not have enough space to fit all the
 * snapshots, -ERANGE is returned and the caller should retry with a
 * larger array.
 *
 * @param io the pool to read from
 * @param snaps where to store the results
 * @param maxlen the number of rados_snap_t that fit in the snaps array
 * @returns number of snapshots on success, negative error code on failure
 * @returns -ERANGE is returned if the snaps array is too short
 */
CEPH_RADOS_API int rados_ioctx_snap_list(rados_ioctx_t io, rados_snap_t *snaps,
                                         int maxlen);

/**
 * Get the id of a pool snapshot
 *
 * @param io the pool to read from
 * @param name the snapshot to find
 * @param id where to store the result
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_ioctx_snap_lookup(rados_ioctx_t io, const char *name,
                                           rados_snap_t *id);

/**
 * Get the name of a pool snapshot
 *
 * @param io the pool to read from
 * @param id the snapshot to find
 * @param name where to store the result
 * @param maxlen the size of the name array
 * @returns 0 on success, negative error code on failure
 * @returns -ERANGE if the name array is too small
 */
CEPH_RADOS_API int rados_ioctx_snap_get_name(rados_ioctx_t io, rados_snap_t id,
                                             char *name, int maxlen);

/**
 * Find when a pool snapshot occurred
 *
 * @param io the pool the snapshot was taken in
 * @param id the snapshot to lookup
 * @param t where to store the result
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_ioctx_snap_get_stamp(rados_ioctx_t io, rados_snap_t id,
                                              time_t *t);

/** @} Snapshots */

/**
 * @name Synchronous I/O
 * Writes are replicated to a number of OSDs based on the
 * configuration of the pool they are in. These write functions block
 * until data is in memory on all replicas of the object they're
 * writing to - they are equivalent to doing the corresponding
 * asynchronous write, and the calling
 * rados_ioctx_wait_for_complete().  For greater data safety, use the
 * asynchronous functions and rados_aio_wait_for_safe().
 *
 * @{
 */

/**
 * Return the version of the last object read or written to.
 *
 * This exposes the internal version number of the last object read or
 * written via this io context
 *
 * @param io the io context to check
 * @returns last read or written object version
 */
CEPH_RADOS_API uint64_t rados_get_last_version(rados_ioctx_t io);

/**
 * Write *len* bytes from *buf* into the *oid* object, starting at
 * offset *off*. The value of *len* must be <= UINT_MAX/2.
 *
 * @note This will never return a positive value not equal to len.
 * @param io the io context in which the write will occur
 * @param oid name of the object
 * @param buf data to write
 * @param len length of the data, in bytes
 * @param off byte offset in the object to begin writing at
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_write(rados_ioctx_t io, const char *oid,
                               const char *buf, size_t len, uint64_t off);

/**
 * Write *len* bytes from *buf* into the *oid* object. The value of
 * *len* must be <= UINT_MAX/2.
 *
 * The object is filled with the provided data. If the object exists,
 * it is atomically truncated and then written.
 *
 * @param io the io context in which the write will occur
 * @param oid name of the object
 * @param buf data to write
 * @param len length of the data, in bytes
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_write_full(rados_ioctx_t io, const char *oid,
                                    const char *buf, size_t len);

/**
 * Write the same *data_len* bytes from *buf* multiple times into the
 * *oid* object. *write_len* bytes are written in total, which must be
 * a multiple of *data_len*. The value of *write_len* and *data_len*
 * must be <= UINT_MAX/2.
 *
 * @param io the io context in which the write will occur
 * @param oid name of the object
 * @param buf data to write
 * @param data_len length of the data, in bytes
 * @param write_len the total number of bytes to write
 * @param off byte offset in the object to begin writing at
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_writesame(rados_ioctx_t io, const char *oid,
                                   const char *buf, size_t data_len,
                                   size_t write_len, uint64_t off);

/**
 * Append *len* bytes from *buf* into the *oid* object. The value of
 * *len* must be <= UINT_MAX/2.
 *
 * @param io the context to operate in
 * @param oid the name of the object
 * @param buf the data to append
 * @param len length of buf (in bytes)
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_append(rados_ioctx_t io, const char *oid,
                                const char *buf, size_t len);

/**
 * Read data from an object
 *
 * The io context determines the snapshot to read from, if any was set
 * by rados_ioctx_snap_set_read().
 *
 * @param io the context in which to perform the read
 * @param oid the name of the object to read from
 * @param buf where to store the results
 * @param len the number of bytes to read
 * @param off the offset to start reading from in the object
 * @returns number of bytes read on success, negative error code on
 * failure
 */
CEPH_RADOS_API int rados_read(rados_ioctx_t io, const char *oid, char *buf,
                              size_t len, uint64_t off);

/**
 * Compute checksum from object data
 *
 * The io context determines the snapshot to checksum, if any was set
 * by rados_ioctx_snap_set_read(). The length of the init_value and
 * resulting checksum are dependent upon the checksum type:
 *
 *    XXHASH64: le64
 *    XXHASH32: le32
 *    CRC32C:	le32
 *
 * The checksum result is encoded the following manner:
 *
 *    le32 num_checksum_chunks
 *    {
 *      leXX checksum for chunk (where XX = appropriate size for the checksum type)
 *    } * num_checksum_chunks
 *
 * @param io the context in which to perform the checksum
 * @param oid the name of the object to checksum
 * @param type the checksum algorithm to utilize
 * @param init_value the init value for the algorithm
 * @param init_value_len the length of the init value
 * @param len the number of bytes to checksum
 * @param off the offset to start checksumming in the object
 * @param chunk_size optional length-aligned chunk size for checksums
 * @param pchecksum where to store the checksum result
 * @param checksum_len the number of bytes available for the result
 * @return negative error code on failure
 */
CEPH_RADOS_API int rados_checksum(rados_ioctx_t io, const char *oid,
				  rados_checksum_type_t type,
				  const char *init_value, size_t init_value_len,
				  size_t len, uint64_t off, size_t chunk_size,
				  char *pchecksum, size_t checksum_len);

/**
 * Delete an object
 *
 * @note This does not delete any snapshots of the object.
 *
 * @param io the pool to delete the object from
 * @param oid the name of the object to delete
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_remove(rados_ioctx_t io, const char *oid);

/**
 * Resize an object
 *
 * If this enlarges the object, the new area is logically filled with
 * zeroes. If this shrinks the object, the excess data is removed.
 *
 * @param io the context in which to truncate
 * @param oid the name of the object
 * @param size the new size of the object in bytes
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_trunc(rados_ioctx_t io, const char *oid,
                               uint64_t size);

/**
 * Compare an on-disk object range with a buffer
 *
 * @param io the context in which to perform the comparison
 * @param o name of the object
 * @param cmp_buf buffer containing bytes to be compared with object contents
 * @param cmp_len length to compare and size of @c cmp_buf in bytes
 * @param off object byte offset at which to start the comparison
 * @returns 0 on success, negative error code on failure,
 *  (-MAX_ERRNO - mismatch_off) on mismatch
 */
CEPH_RADOS_API int rados_cmpext(rados_ioctx_t io, const char *o,
                                const char *cmp_buf, size_t cmp_len,
                                uint64_t off);

/**
 * @name Xattrs
 * Extended attributes are stored as extended attributes on the files
 * representing an object on the OSDs. Thus, they have the same
 * limitations as the underlying filesystem. On ext4, this means that
 * the total data stored in xattrs cannot exceed 4KB.
 *
 * @{
 */

/**
 * Get the value of an extended attribute on an object.
 *
 * @param io the context in which the attribute is read
 * @param o name of the object
 * @param name which extended attribute to read
 * @param buf where to store the result
 * @param len size of buf in bytes
 * @returns length of xattr value on success, negative error code on failure
 */
CEPH_RADOS_API int rados_getxattr(rados_ioctx_t io, const char *o,
                                  const char *name, char *buf, size_t len);

/**
 * Set an extended attribute on an object.
 *
 * @param io the context in which xattr is set
 * @param o name of the object
 * @param name which extended attribute to set
 * @param buf what to store in the xattr
 * @param len the number of bytes in buf
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_setxattr(rados_ioctx_t io, const char *o,
                                  const char *name, const char *buf,
                                  size_t len);

/**
 * Delete an extended attribute from an object.
 *
 * @param io the context in which to delete the xattr
 * @param o the name of the object
 * @param name which xattr to delete
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_rmxattr(rados_ioctx_t io, const char *o,
                                 const char *name);

/**
 * Start iterating over xattrs on an object.
 *
 * @post iter is a valid iterator
 *
 * @param io the context in which to list xattrs
 * @param oid name of the object
 * @param iter where to store the iterator
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_getxattrs(rados_ioctx_t io, const char *oid,
                                   rados_xattrs_iter_t *iter);

/**
 * Get the next xattr on the object
 *
 * @pre iter is a valid iterator
 *
 * @post name is the NULL-terminated name of the next xattr, and val
 * contains the value of the xattr, which is of length len. If the end
 * of the list has been reached, name and val are NULL, and len is 0.
 *
 * @param iter iterator to advance
 * @param name where to store the name of the next xattr
 * @param val where to store the value of the next xattr
 * @param len the number of bytes in val
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_getxattrs_next(rados_xattrs_iter_t iter,
                                        const char **name, const char **val,
                                        size_t *len);

/**
 * Close the xattr iterator.
 *
 * iter should not be used after this is called.
 *
 * @param iter the iterator to close
 */
CEPH_RADOS_API void rados_getxattrs_end(rados_xattrs_iter_t iter);

/** @} Xattrs */

/**
 * Get the next omap key/value pair on the object
 *
 * @pre iter is a valid iterator
 *
 * @post key and val are the next key/value pair. key is
 * null-terminated, and val has length len. If the end of the list has
 * been reached, key and val are NULL, and len is 0. key and val will
 * not be accessible after rados_omap_get_end() is called on iter, so
 * if they are needed after that they should be copied.
 *
 * @param iter iterator to advance
 * @param key where to store the key of the next omap entry
 * @param val where to store the value of the next omap entry
 * @param len where to store the number of bytes in val
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_omap_get_next(rados_omap_iter_t iter,
                                       char **key,
                                       char **val,
                                       size_t *len);

/**
 * Get the next omap key/value pair on the object. Note that it's
 * perfectly safe to mix calls to rados_omap_get_next and
 * rados_omap_get_next2.
 *
 * @pre iter is a valid iterator
 *
 * @post key and val are the next key/value pair. key has length
 * keylen and val has length vallen. If the end of the list has
 * been reached, key and val are NULL, and keylen and vallen is 0.
 * key and val will not be accessible after rados_omap_get_end()
 * is called on iter, so if they are needed after that they
 * should be copied.
 *
 * @param iter iterator to advance
 * @param key where to store the key of the next omap entry
 * @param val where to store the value of the next omap entry
 * @param key_len where to store the number of bytes in key
 * @param val_len where to store the number of bytes in val
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_omap_get_next2(rados_omap_iter_t iter,
                                       char **key,
                                       char **val,
                                       size_t *key_len,
                                       size_t *val_len);

/**
 * Return number of elements in the iterator
 *
 * @param iter the iterator of which to return the size
 */
CEPH_RADOS_API unsigned int rados_omap_iter_size(rados_omap_iter_t iter);

/**
 * Close the omap iterator.
 *
 * iter should not be used after this is called.
 *
 * @param iter the iterator to close
 */
CEPH_RADOS_API void rados_omap_get_end(rados_omap_iter_t iter);

/**
 * Get object stats (size/mtime)
 *
 * TODO: when are these set, and by whom? can they be out of date?
 *
 * @param io ioctx
 * @param o object name
 * @param psize where to store object size
 * @param pmtime where to store modification time
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_stat(rados_ioctx_t io, const char *o, uint64_t *psize,
                              time_t *pmtime);
/**
 * Execute an OSD class method on an object
 *
 * The OSD has a plugin mechanism for performing complicated
 * operations on an object atomically. These plugins are called
 * classes. This function allows librados users to call the custom
 * methods. The input and output formats are defined by the class.
 * Classes in ceph.git can be found in src/cls subdirectories
 *
 * @param io the context in which to call the method
 * @param oid the object to call the method on
 * @param cls the name of the class
 * @param method the name of the method
 * @param in_buf where to find input
 * @param in_len length of in_buf in bytes
 * @param buf where to store output
 * @param out_len length of buf in bytes
 * @returns the length of the output, or
 * -ERANGE if out_buf does not have enough space to store it (For methods that return data). For
 * methods that don't return data, the return value is
 * method-specific.
 */
CEPH_RADOS_API int rados_exec(rados_ioctx_t io, const char *oid,
                              const char *cls, const char *method,
	                      const char *in_buf, size_t in_len, char *buf,
                              size_t out_len);


/** @} Synchronous I/O */

/**
 * @name Asynchronous I/O
 * Read and write to objects without blocking.
 *
 * @{
 */

/**
 * @typedef rados_callback_t
 * Callbacks for asynchrous operations take two parameters:
 * - cb the completion that has finished
 * - arg application defined data made available to the callback function
 */
typedef void (*rados_callback_t)(rados_completion_t cb, void *arg);

/**
 * Constructs a completion to use with asynchronous operations
 *
 * The complete and safe callbacks correspond to operations being
 * acked and committed, respectively. The callbacks are called in
 * order of receipt, so the safe callback may be triggered before the
 * complete callback, and vice versa. This is affected by journalling
 * on the OSDs.
 *
 * TODO: more complete documentation of this elsewhere (in the RADOS docs?)
 *
 * @note Read operations only get a complete callback.
 * @note BUG: this should check for ENOMEM instead of throwing an exception
 *
 * @param cb_arg application-defined data passed to the callback functions
 * @param cb_complete the function to be called when the operation is
 * in memory on all replicas
 * @param cb_safe the function to be called when the operation is on
 * stable storage on all replicas
 * @param pc where to store the completion
 * @returns 0
 */
CEPH_RADOS_API int rados_aio_create_completion(void *cb_arg,
                                               rados_callback_t cb_complete,
                                               rados_callback_t cb_safe,
				               rados_completion_t *pc);

/**
 * Constructs a completion to use with asynchronous operations
 *
 * The complete callback corresponds to operation being acked.
 *
 * @note BUG: this should check for ENOMEM instead of throwing an exception
 *
 * @param cb_arg application-defined data passed to the callback functions
 * @param cb_complete the function to be called when the operation is committed
 * on all replicas
 * @param pc where to store the completion
 * @returns 0
 */
CEPH_RADOS_API int rados_aio_create_completion2(void *cb_arg,
						rados_callback_t cb_complete,
						rados_completion_t *pc);

/**
 * Block until an operation completes
 *
 * This means it is in memory on all replicas.
 *
 * @note BUG: this should be void
 *
 * @param c operation to wait for
 * @returns 0
 */
CEPH_RADOS_API int rados_aio_wait_for_complete(rados_completion_t c);

/**
 * Block until an operation is safe
 *
 * This means it is on stable storage on all replicas.
 *
 * @note BUG: this should be void
 *
 * @param c operation to wait for
 * @returns 0
 */
CEPH_RADOS_API int rados_aio_wait_for_safe(rados_completion_t c)
  __attribute__((deprecated));

/**
 * Has an asynchronous operation completed?
 *
 * @warning This does not imply that the complete callback has
 * finished
 *
 * @param c async operation to inspect
 * @returns whether c is complete
 */
CEPH_RADOS_API int rados_aio_is_complete(rados_completion_t c);

/**
 * Is an asynchronous operation safe?
 *
 * @warning This does not imply that the safe callback has
 * finished
 *
 * @param c async operation to inspect
 * @returns whether c is safe
 */
CEPH_RADOS_API int rados_aio_is_safe(rados_completion_t c);

/**
 * Block until an operation completes and callback completes
 *
 * This means it is in memory on all replicas and can be read.
 *
 * @note BUG: this should be void
 *
 * @param c operation to wait for
 * @returns 0
 */
CEPH_RADOS_API int rados_aio_wait_for_complete_and_cb(rados_completion_t c);

/**
 * Block until an operation is safe and callback has completed
 *
 * This means it is on stable storage on all replicas.
 *
 * @note BUG: this should be void
 *
 * @param c operation to wait for
 * @returns 0
 */
CEPH_RADOS_API int rados_aio_wait_for_safe_and_cb(rados_completion_t c)
  __attribute__((deprecated));

/**
 * Has an asynchronous operation and callback completed
 *
 * @param c async operation to inspect
 * @returns whether c is complete
 */
CEPH_RADOS_API int rados_aio_is_complete_and_cb(rados_completion_t c);

/**
 * Is an asynchronous operation safe and has the callback completed
 *
 * @param c async operation to inspect
 * @returns whether c is safe
 */
CEPH_RADOS_API int rados_aio_is_safe_and_cb(rados_completion_t c);

/**
 * Get the return value of an asychronous operation
 *
 * The return value is set when the operation is complete or safe,
 * whichever comes first.
 *
 * @pre The operation is safe or complete
 *
 * @note BUG: complete callback may never be called when the safe
 * message is received before the complete message
 *
 * @param c async operation to inspect
 * @returns return value of the operation
 */
CEPH_RADOS_API int rados_aio_get_return_value(rados_completion_t c);

/**
 * Get the internal object version of the target of an asychronous operation
 *
 * The return value is set when the operation is complete or safe,
 * whichever comes first.
 *
 * @pre The operation is safe or complete
 *
 * @note BUG: complete callback may never be called when the safe
 * message is received before the complete message
 *
 * @param c async operation to inspect
 * @returns version number of the asychronous operation's target
 */
CEPH_RADOS_API uint64_t rados_aio_get_version(rados_completion_t c);

/**
 * Release a completion
 *
 * Call this when you no longer need the completion. It may not be
 * freed immediately if the operation is not acked and committed.
 *
 * @param c completion to release
 */
CEPH_RADOS_API void rados_aio_release(rados_completion_t c);

/**
 * Write data to an object asynchronously
 *
 * Queues the write and returns. The return value of the completion
 * will be 0 on success, negative error code on failure.
 *
 * @param io the context in which the write will occur
 * @param oid name of the object
 * @param completion what to do when the write is safe and complete
 * @param buf data to write
 * @param len length of the data, in bytes
 * @param off byte offset in the object to begin writing at
 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
 * other than LIBRADOS_SNAP_HEAD
 */
CEPH_RADOS_API int rados_aio_write(rados_ioctx_t io, const char *oid,
		                   rados_completion_t completion,
		                   const char *buf, size_t len, uint64_t off);

/**
 * Asynchronously append data to an object
 *
 * Queues the append and returns.
 *
 * The return value of the completion will be 0 on success, negative
 * error code on failure.
 *
 * @param io the context to operate in
 * @param oid the name of the object
 * @param completion what to do when the append is safe and complete
 * @param buf the data to append
 * @param len length of buf (in bytes)
 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
 * other than LIBRADOS_SNAP_HEAD
 */
CEPH_RADOS_API int rados_aio_append(rados_ioctx_t io, const char *oid,
		                    rados_completion_t completion,
		                    const char *buf, size_t len);

/**
 * Asynchronously write an entire object
 *
 * The object is filled with the provided data. If the object exists,
 * it is atomically truncated and then written.
 * Queues the write_full and returns.
 *
 * The return value of the completion will be 0 on success, negative
 * error code on failure.
 *
 * @param io the io context in which the write will occur
 * @param oid name of the object
 * @param completion what to do when the write_full is safe and complete
 * @param buf data to write
 * @param len length of the data, in bytes
 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
 * other than LIBRADOS_SNAP_HEAD
 */
CEPH_RADOS_API int rados_aio_write_full(rados_ioctx_t io, const char *oid,
			                rados_completion_t completion,
			                const char *buf, size_t len);

/**
 * Asynchronously write the same buffer multiple times
 *
 * Queues the writesame and returns.
 *
 * The return value of the completion will be 0 on success, negative
 * error code on failure.
 *
 * @param io the io context in which the write will occur
 * @param oid name of the object
 * @param completion what to do when the writesame is safe and complete
 * @param buf data to write
 * @param data_len length of the data, in bytes
 * @param write_len the total number of bytes to write
 * @param off byte offset in the object to begin writing at
 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
 * other than LIBRADOS_SNAP_HEAD
 */
CEPH_RADOS_API int rados_aio_writesame(rados_ioctx_t io, const char *oid,
			               rados_completion_t completion,
			               const char *buf, size_t data_len,
				       size_t write_len, uint64_t off);

/**
 * Asynchronously remove an object
 *
 * Queues the remove and returns.
 *
 * The return value of the completion will be 0 on success, negative
 * error code on failure.
 *
 * @param io the context to operate in
 * @param oid the name of the object
 * @param completion what to do when the remove is safe and complete
 * @returns 0 on success, -EROFS if the io context specifies a snap_seq
 * other than LIBRADOS_SNAP_HEAD
 */
CEPH_RADOS_API int rados_aio_remove(rados_ioctx_t io, const char *oid,
		                    rados_completion_t completion);

/**
 * Asynchronously read data from an object
 *
 * The io context determines the snapshot to read from, if any was set
 * by rados_ioctx_snap_set_read().
 *
 * The return value of the completion will be number of bytes read on
 * success, negative error code on failure.
 *
 * @note only the 'complete' callback of the completion will be called.
 *
 * @param io the context in which to perform the read
 * @param oid the name of the object to read from
 * @param completion what to do when the read is complete
 * @param buf where to store the results
 * @param len the number of bytes to read
 * @param off the offset to start reading from in the object
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_read(rados_ioctx_t io, const char *oid,
		                  rados_completion_t completion,
		                  char *buf, size_t len, uint64_t off);

/**
 * Block until all pending writes in an io context are safe
 *
 * This is not equivalent to calling rados_aio_wait_for_safe() on all
 * write completions, since this waits for the associated callbacks to
 * complete as well.
 *
 * @note BUG: always returns 0, should be void or accept a timeout
 *
 * @param io the context to flush
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_flush(rados_ioctx_t io);


/**
 * Schedule a callback for when all currently pending
 * aio writes are safe. This is a non-blocking version of
 * rados_aio_flush().
 *
 * @param io the context to flush
 * @param completion what to do when the writes are safe
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_flush_async(rados_ioctx_t io,
                                         rados_completion_t completion);


/**
 * Asynchronously get object stats (size/mtime)
 *
 * @param io ioctx
 * @param o object name
 * @param completion what to do when the stat is complete
 * @param psize where to store object size
 * @param pmtime where to store modification time
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_stat(rados_ioctx_t io, const char *o,
		                  rados_completion_t completion,
		                  uint64_t *psize, time_t *pmtime);

/**
 * Asynchronously compare an on-disk object range with a buffer
 *
 * @param io the context in which to perform the comparison
 * @param o the name of the object to compare with
 * @param completion what to do when the comparison is complete
 * @param cmp_buf buffer containing bytes to be compared with object contents
 * @param cmp_len length to compare and size of @c cmp_buf in bytes
 * @param off object byte offset at which to start the comparison
 * @returns 0 on success, negative error code on failure,
 *  (-MAX_ERRNO - mismatch_off) on mismatch
 */
CEPH_RADOS_API int rados_aio_cmpext(rados_ioctx_t io, const char *o,
                                    rados_completion_t completion,
                                    const char *cmp_buf,
                                    size_t cmp_len,
                                    uint64_t off);

/**
 * Cancel async operation
 *
 * @param io ioctx
 * @param completion completion handle
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_cancel(rados_ioctx_t io,
                                    rados_completion_t completion);

/**
 * Asynchronously execute an OSD class method on an object
 *
 * The OSD has a plugin mechanism for performing complicated
 * operations on an object atomically. These plugins are called
 * classes. This function allows librados users to call the custom
 * methods. The input and output formats are defined by the class.
 * Classes in ceph.git can be found in src/cls subdirectories
 *
 * @param io the context in which to call the method
 * @param o name of the object
 * @param completion what to do when the exec completes
 * @param cls the name of the class
 * @param method the name of the method
 * @param in_buf where to find input
 * @param in_len length of in_buf in bytes
 * @param buf where to store output
 * @param out_len length of buf in bytes
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_exec(rados_ioctx_t io, const char *o,
				  rados_completion_t completion,
				  const char *cls, const char *method,
				  const char *in_buf, size_t in_len,
				  char *buf, size_t out_len);

/** @} Asynchronous I/O */

/**
 * @name Asynchronous Xattrs
 * Extended attributes are stored as extended attributes on the files
 * representing an object on the OSDs. Thus, they have the same
 * limitations as the underlying filesystem. On ext4, this means that
 * the total data stored in xattrs cannot exceed 4KB.
 *
 * @{
 */

/**
 * Asynchronously get the value of an extended attribute on an object.
 *
 * @param io the context in which the attribute is read
 * @param o name of the object
 * @param completion what to do when the getxattr completes
 * @param name which extended attribute to read
 * @param buf where to store the result
 * @param len size of buf in bytes
 * @returns length of xattr value on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_getxattr(rados_ioctx_t io, const char *o,
				      rados_completion_t completion,
				      const char *name, char *buf, size_t len);

/**
 * Asynchronously set an extended attribute on an object.
 *
 * @param io the context in which xattr is set
 * @param o name of the object
 * @param completion what to do when the setxattr completes
 * @param name which extended attribute to set
 * @param buf what to store in the xattr
 * @param len the number of bytes in buf
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_setxattr(rados_ioctx_t io, const char *o,
				      rados_completion_t completion,
				      const char *name, const char *buf,
				      size_t len);

/**
 * Asynchronously delete an extended attribute from an object.
 *
 * @param io the context in which to delete the xattr
 * @param o the name of the object
 * @param completion what to do when the rmxattr completes
 * @param name which xattr to delete
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_rmxattr(rados_ioctx_t io, const char *o,
				     rados_completion_t completion,
				     const char *name);

/**
 * Asynchronously start iterating over xattrs on an object.
 *
 * @post iter is a valid iterator
 *
 * @param io the context in which to list xattrs
 * @param oid name of the object
 * @param completion what to do when the getxattrs completes
 * @param iter where to store the iterator
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_getxattrs(rados_ioctx_t io, const char *oid,
				       rados_completion_t completion,
				       rados_xattrs_iter_t *iter);

/** @} Asynchronous Xattrs */

/**
 * @name Watch/Notify
 *
 * Watch/notify is a protocol to help communicate among clients. It
 * can be used to sychronize client state. All that's needed is a
 * well-known object name (for example, rbd uses the header object of
 * an image).
 *
 * Watchers register an interest in an object, and receive all
 * notifies on that object. A notify attempts to communicate with all
 * clients watching an object, and blocks on the notifier until each
 * client responds or a timeout is reached.
 *
 * See rados_watch() and rados_notify() for more details.
 *
 * @{
 */

/**
 * @typedef rados_watchcb_t
 *
 * Callback activated when a notify is received on a watched
 * object.
 *
 * @param opcode undefined
 * @param ver version of the watched object
 * @param arg application-specific data
 *
 * @note BUG: opcode is an internal detail that shouldn't be exposed
 * @note BUG: ver is unused
 */
typedef void (*rados_watchcb_t)(uint8_t opcode, uint64_t ver, void *arg);

/**
 * @typedef rados_watchcb2_t
 *
 * Callback activated when a notify is received on a watched
 * object.
 *
 * @param arg opaque user-defined value provided to rados_watch2()
 * @param notify_id an id for this notify event
 * @param handle the watcher handle we are notifying
 * @param notifier_id the unique client id for the notifier
 * @param data payload from the notifier
 * @param datalen length of payload buffer
 */
typedef void (*rados_watchcb2_t)(void *arg,
				 uint64_t notify_id,
				 uint64_t handle,
				 uint64_t notifier_id,
				 void *data,
				 size_t data_len);

/**
 * @typedef rados_watcherrcb_t
 *
 * Callback activated when we encounter an error with the watch session.
 * This can happen when the location of the objects moves within the
 * cluster and we fail to register our watch with the new object location,
 * or when our connection with the object OSD is otherwise interrupted and
 * we may have missed notify events.
 *
 * @param pre opaque user-defined value provided to rados_watch2()
 * @param err error code
 */
  typedef void (*rados_watcherrcb_t)(void *pre, uint64_t cookie, int err);

/**
 * Register an interest in an object
 *
 * A watch operation registers the client as being interested in
 * notifications on an object. OSDs keep track of watches on
 * persistent storage, so they are preserved across cluster changes by
 * the normal recovery process. If the client loses its connection to
 * the primary OSD for a watched object, the watch will be removed
 * after 30 seconds. Watches are automatically reestablished when a new
 * connection is made, or a placement group switches OSDs.
 *
 * @note BUG: librados should provide a way for watchers to notice connection resets
 * @note BUG: the ver parameter does not work, and -ERANGE will never be returned
 *            (See URL tracker.ceph.com/issues/2592)
 *
 * @param io the pool the object is in
 * @param o the object to watch
 * @param ver expected version of the object
 * @param cookie where to store the internal id assigned to this watch
 * @param watchcb what to do when a notify is received on this object
 * @param arg application defined data to pass when watchcb is called
 * @returns 0 on success, negative error code on failure
 * @returns -ERANGE if the version of the object is greater than ver
 */
CEPH_RADOS_API int rados_watch(rados_ioctx_t io, const char *o, uint64_t ver,
			       uint64_t *cookie,
			       rados_watchcb_t watchcb, void *arg)
  __attribute__((deprecated));


/**
 * Register an interest in an object
 *
 * A watch operation registers the client as being interested in
 * notifications on an object. OSDs keep track of watches on
 * persistent storage, so they are preserved across cluster changes by
 * the normal recovery process. If the client loses its connection to the
 * primary OSD for a watched object, the watch will be removed after
 * a timeout configured with osd_client_watch_timeout.
 * Watches are automatically reestablished when a new
 * connection is made, or a placement group switches OSDs.
 *
 * @param io the pool the object is in
 * @param o the object to watch
 * @param cookie where to store the internal id assigned to this watch
 * @param watchcb what to do when a notify is received on this object
 * @param watcherrcb what to do when the watch session encounters an error
 * @param arg opaque value to pass to the callback
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_watch2(rados_ioctx_t io, const char *o, uint64_t *cookie,
				rados_watchcb2_t watchcb,
				rados_watcherrcb_t watcherrcb,
				void *arg);

/**
 * Register an interest in an object
 *
 * A watch operation registers the client as being interested in
 * notifications on an object. OSDs keep track of watches on
 * persistent storage, so they are preserved across cluster changes by
 * the normal recovery process. Watches are automatically reestablished when a new
 * connection is made, or a placement group switches OSDs.
 *
 * @param io the pool the object is in
 * @param o the object to watch
 * @param cookie where to store the internal id assigned to this watch
 * @param watchcb what to do when a notify is received on this object
 * @param watcherrcb what to do when the watch session encounters an error
 * @param timeout how many seconds the connection will keep after disconnection
 * @param arg opaque value to pass to the callback
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_watch3(rados_ioctx_t io, const char *o, uint64_t *cookie,
        rados_watchcb2_t watchcb,
        rados_watcherrcb_t watcherrcb,
        uint32_t timeout,
        void *arg);

/**
 * Asynchronous register an interest in an object
 *
 * A watch operation registers the client as being interested in
 * notifications on an object. OSDs keep track of watches on
 * persistent storage, so they are preserved across cluster changes by
 * the normal recovery process. If the client loses its connection to
 * the primary OSD for a watched object, the watch will be removed
 * after 30 seconds. Watches are automatically reestablished when a new
 * connection is made, or a placement group switches OSDs.
 *
 * @param io the pool the object is in
 * @param o the object to watch
 * @param completion what to do when operation has been attempted
 * @param handle where to store the internal id assigned to this watch
 * @param watchcb what to do when a notify is received on this object
 * @param watcherrcb what to do when the watch session encounters an error
 * @param arg opaque value to pass to the callback
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_watch(rados_ioctx_t io, const char *o,
				   rados_completion_t completion, uint64_t *handle,
				   rados_watchcb2_t watchcb,
				   rados_watcherrcb_t watcherrcb,
				   void *arg);

/**
 * Asynchronous register an interest in an object
 *
 * A watch operation registers the client as being interested in
 * notifications on an object. OSDs keep track of watches on
 * persistent storage, so they are preserved across cluster changes by
 * the normal recovery process. If the client loses its connection to
 * the primary OSD for a watched object, the watch will be removed
 * after the number of seconds that configured in timeout parameter.
 * Watches are automatically reestablished when a new
 * connection is made, or a placement group switches OSDs.
 *
 * @param io the pool the object is in
 * @param o the object to watch
 * @param completion what to do when operation has been attempted
 * @param handle where to store the internal id assigned to this watch
 * @param watchcb what to do when a notify is received on this object
 * @param watcherrcb what to do when the watch session encounters an error
 * @param timeout how many seconds the connection will keep after disconnection
 * @param arg opaque value to pass to the callback
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_watch2(rados_ioctx_t io, const char *o,
           rados_completion_t completion, uint64_t *handle,
           rados_watchcb2_t watchcb,
           rados_watcherrcb_t watcherrcb,
           uint32_t timeout,
           void *arg);

/**
 * Check on the status of a watch
 *
 * Return the number of milliseconds since the watch was last confirmed.
 * Or, if there has been an error, return that.
 *
 * If there is an error, the watch is no longer valid, and should be
 * destroyed with rados_unwatch2().  The the user is still interested
 * in the object, a new watch should be created with rados_watch2().
 *
 * @param io the pool the object is in
 * @param cookie the watch handle
 * @returns ms since last confirmed on success, negative error code on failure
 */
CEPH_RADOS_API int rados_watch_check(rados_ioctx_t io, uint64_t cookie);

/**
 * Unregister an interest in an object
 *
 * Once this completes, no more notifies will be sent to us for this
 * watch. This should be called to clean up unneeded watchers.
 *
 * @param io the pool the object is in
 * @param o the name of the watched object (ignored)
 * @param cookie which watch to unregister
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_unwatch(rados_ioctx_t io, const char *o, uint64_t cookie)
  __attribute__((deprecated));

/**
 * Unregister an interest in an object
 *
 * Once this completes, no more notifies will be sent to us for this
 * watch. This should be called to clean up unneeded watchers.
 *
 * @param io the pool the object is in
 * @param cookie which watch to unregister
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_unwatch2(rados_ioctx_t io, uint64_t cookie);

/**
 * Asynchronous unregister an interest in an object
 *
 * Once this completes, no more notifies will be sent to us for this
 * watch. This should be called to clean up unneeded watchers.
 *
 * @param io the pool the object is in
 * @param completion what to do when operation has been attempted
 * @param cookie which watch to unregister
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_unwatch(rados_ioctx_t io, uint64_t cookie,
                                     rados_completion_t completion);

/**
 * Sychronously notify watchers of an object
 *
 * This blocks until all watchers of the object have received and
 * reacted to the notify, or a timeout is reached.
 *
 * @note BUG: the timeout is not changeable via the C API
 * @note BUG: the bufferlist is inaccessible in a rados_watchcb_t
 *
 * @param io the pool the object is in
 * @param o the name of the object
 * @param ver obsolete - just pass zero
 * @param buf data to send to watchers
 * @param buf_len length of buf in bytes
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_notify(rados_ioctx_t io, const char *o, uint64_t ver,
				const char *buf, int buf_len)
  __attribute__((deprecated));

/**
 * Sychronously notify watchers of an object
 *
 * This blocks until all watchers of the object have received and
 * reacted to the notify, or a timeout is reached.
 *
 * The reply buffer is optional.  If specified, the client will get
 * back an encoded buffer that includes the ids of the clients that
 * acknowledged the notify as well as their notify ack payloads (if
 * any).  Clients that timed out are not included.  Even clients that
 * do not include a notify ack payload are included in the list but
 * have a 0-length payload associated with them.  The format:
 *
 *    le32 num_acks
 *    {
 *      le64 gid     global id for the client (for client.1234 that's 1234)
 *      le64 cookie  cookie for the client
 *      le32 buflen  length of reply message buffer
 *      u8 * buflen  payload
 *    } * num_acks
 *    le32 num_timeouts
 *    {
 *      le64 gid     global id for the client
 *      le64 cookie  cookie for the client
 *    } * num_timeouts
 *
 * Note: There may be multiple instances of the same gid if there are
 * multiple watchers registered via the same client.
 *
 * Note: The buffer must be released with rados_buffer_free() when the
 * user is done with it.
 *
 * Note: Since the result buffer includes clients that time out, it
 * will be set even when rados_notify() returns an error code (like
 * -ETIMEDOUT).
 *
 * @param io the pool the object is in
 * @param completion what to do when operation has been attempted
 * @param o the name of the object
 * @param buf data to send to watchers
 * @param buf_len length of buf in bytes
 * @param timeout_ms notify timeout (in ms)
 * @param reply_buffer pointer to reply buffer pointer (free with rados_buffer_free)
 * @param reply_buffer_len pointer to size of reply buffer
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_notify(rados_ioctx_t io, const char *o,
				    rados_completion_t completion,
				    const char *buf, int buf_len,
				    uint64_t timeout_ms, char **reply_buffer,
				    size_t *reply_buffer_len);
CEPH_RADOS_API int rados_notify2(rados_ioctx_t io, const char *o,
				 const char *buf, int buf_len,
				 uint64_t timeout_ms,
				 char **reply_buffer, size_t *reply_buffer_len);

/**
 * Decode a notify response
 *
 * Decode a notify response (from rados_aio_notify() call) into acks and
 * timeout arrays.
 *
 * @param reply_buffer buffer from rados_aio_notify() call
 * @param reply_buffer_len reply_buffer length
 * @param acks pointer to struct notify_ack_t pointer
 * @param nr_acks pointer to ack count
 * @param timeouts pointer to notify_timeout_t pointer
 * @param nr_timeouts pointer to timeout count
 * @returns 0 on success
 */
CEPH_RADOS_API int rados_decode_notify_response(char *reply_buffer, size_t reply_buffer_len,
                                                struct notify_ack_t **acks, size_t *nr_acks,
                                                struct notify_timeout_t **timeouts, size_t *nr_timeouts);

/**
 * Free notify allocated buffer
 *
 * Release memory allocated by rados_decode_notify_response() call
 *
 * @param acks notify_ack_t struct (from rados_decode_notify_response())
 * @param nr_acks ack count
 * @param timeouts notify_timeout_t struct (from rados_decode_notify_response())
 */
CEPH_RADOS_API void rados_free_notify_response(struct notify_ack_t *acks, size_t nr_acks,
                                               struct notify_timeout_t *timeouts);

/**
 * Acknolwedge receipt of a notify
 *
 * @param io the pool the object is in
 * @param o the name of the object
 * @param notify_id the notify_id we got on the watchcb2_t callback
 * @param cookie the watcher handle
 * @param buf payload to return to notifier (optional)
 * @param buf_len payload length
 * @returns 0 on success
 */
CEPH_RADOS_API int rados_notify_ack(rados_ioctx_t io, const char *o,
				    uint64_t notify_id, uint64_t cookie,
				    const char *buf, int buf_len);

/**
 * Flush watch/notify callbacks
 *
 * This call will block until all pending watch/notify callbacks have
 * been executed and the queue is empty.  It should usually be called
 * after shutting down any watches before shutting down the ioctx or
 * librados to ensure that any callbacks do not misuse the ioctx (for
 * example by calling rados_notify_ack after the ioctx has been
 * destroyed).
 *
 * @param cluster the cluster handle
 */
CEPH_RADOS_API int rados_watch_flush(rados_t cluster);
/**
 * Flush watch/notify callbacks
 *
 * This call will be nonblock, and the completion will be called
 * until all pending watch/notify callbacks have been executed and
 * the queue is empty.  It should usually be called after shutting
 * down any watches before shutting down the ioctx or
 * librados to ensure that any callbacks do not misuse the ioctx (for
 * example by calling rados_notify_ack after the ioctx has been
 * destroyed).
 *
 * @param cluster the cluster handle
 * @param completion what to do when operation has been attempted
 */
CEPH_RADOS_API int rados_aio_watch_flush(rados_t cluster, rados_completion_t completion);

/** @} Watch/Notify */

/**
 * Pin an object in the cache tier
 *
 * When an object is pinned in the cache tier, it stays in the cache
 * tier, and won't be flushed out.
 *
 * @param io the pool the object is in
 * @param o the object id
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_cache_pin(rados_ioctx_t io, const char *o);

/**
 * Unpin an object in the cache tier
 *
 * After an object is unpinned in the cache tier, it can be flushed out
 *
 * @param io the pool the object is in
 * @param o the object id
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_cache_unpin(rados_ioctx_t io, const char *o);

/**
 * @name Hints
 *
 * @{
 */

/**
 * Set allocation hint for an object
 *
 * This is an advisory operation, it will always succeed (as if it was
 * submitted with a LIBRADOS_OP_FLAG_FAILOK flag set) and is not
 * guaranteed to do anything on the backend.
 *
 * @param io the pool the object is in
 * @param o the name of the object
 * @param expected_object_size expected size of the object, in bytes
 * @param expected_write_size expected size of writes to the object, in bytes
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_set_alloc_hint(rados_ioctx_t io, const char *o,
                                        uint64_t expected_object_size,
                                        uint64_t expected_write_size);

/**
 * Set allocation hint for an object
 *
 * This is an advisory operation, it will always succeed (as if it was
 * submitted with a LIBRADOS_OP_FLAG_FAILOK flag set) and is not
 * guaranteed to do anything on the backend.
 *
 * @param io the pool the object is in
 * @param o the name of the object
 * @param expected_object_size expected size of the object, in bytes
 * @param expected_write_size expected size of writes to the object, in bytes
 * @param flags hints about future IO patterns
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_set_alloc_hint2(rados_ioctx_t io, const char *o,
					 uint64_t expected_object_size,
					 uint64_t expected_write_size,
					 uint32_t flags);

/** @} Hints */

/**
 * @name Object Operations
 *
 * A single rados operation can do multiple operations on one object
 * atomically. The whole operation will succeed or fail, and no partial
 * results will be visible.
 *
 * Operations may be either reads, which can return data, or writes,
 * which cannot. The effects of writes are applied and visible all at
 * once, so an operation that sets an xattr and then checks its value
 * will not see the updated value.
 *
 * @{
 */

/**
 * Create a new rados_write_op_t write operation. This will store all actions
 * to be performed atomically. You must call rados_release_write_op when you are
 * finished with it.
 *
 * @note the ownership of a write operartion is passed to the function
 *       performing the operation, so the same instance of @c rados_write_op_t
 *       cannot be used again after being performed.
 *
 * @returns non-NULL on success, NULL on memory allocation error.
 */
CEPH_RADOS_API rados_write_op_t rados_create_write_op(void);

/**
 * Free a rados_write_op_t, must be called when you're done with it.
 * @param write_op operation to deallocate, created with rados_create_write_op
 */
CEPH_RADOS_API void rados_release_write_op(rados_write_op_t write_op);

/**
 * Set flags for the last operation added to this write_op.
 * At least one op must have been added to the write_op.
 * @param write_op operation to add this action to
 * @param flags see librados.h constants beginning with LIBRADOS_OP_FLAG
 */
CEPH_RADOS_API void rados_write_op_set_flags(rados_write_op_t write_op,
                                             int flags);

/**
 * Ensure that the object exists before writing
 * @param write_op operation to add this action to
 */
CEPH_RADOS_API void rados_write_op_assert_exists(rados_write_op_t write_op);

/**
 * Ensure that the object exists and that its internal version
 * number is equal to "ver" before writing. "ver" should be a
 * version number previously obtained with rados_get_last_version().
 * - If the object's version is greater than the asserted version
 *   then rados_write_op_operate will return -ERANGE instead of
 *   executing the op.
 * - If the object's version is less than the asserted version
 *   then rados_write_op_operate will return -EOVERFLOW instead
 *   of executing the op.
 * @param write_op operation to add this action to
 * @param ver object version number
 */
CEPH_RADOS_API void rados_write_op_assert_version(rados_write_op_t write_op, uint64_t ver);

/**
 * Ensure that given object range (extent) satisfies comparison.
 *
 * @param write_op operation to add this action to
 * @param cmp_buf buffer containing bytes to be compared with object contents
 * @param cmp_len length to compare and size of @c cmp_buf in bytes
 * @param off object byte offset at which to start the comparison
 * @param prval returned result of comparison, 0 on success, negative error code
 *  on failure, (-MAX_ERRNO - mismatch_off) on mismatch
 */
CEPH_RADOS_API void rados_write_op_cmpext(rados_write_op_t write_op,
                                          const char *cmp_buf,
                                          size_t cmp_len,
                                          uint64_t off,
                                          int *prval);

/**
 * Ensure that given xattr satisfies comparison.
 * If the comparison is not satisfied, the return code of the
 * operation will be -ECANCELED
 * @param write_op operation to add this action to
 * @param name name of the xattr to look up
 * @param comparison_operator currently undocumented, look for
 * LIBRADOS_CMPXATTR_OP_EQ in librados.h
 * @param value buffer to compare actual xattr value to
 * @param value_len length of buffer to compare actual xattr value to
 */
CEPH_RADOS_API void rados_write_op_cmpxattr(rados_write_op_t write_op,
                                            const char *name,
                                            uint8_t comparison_operator,
                                            const char *value,
                                            size_t value_len);

/**
 * Ensure that the an omap value satisfies a comparison,
 * with the supplied value on the right hand side (i.e.
 * for OP_LT, the comparison is actual_value < value.
 *
 * @param write_op operation to add this action to
 * @param key which omap value to compare
 * @param comparison_operator one of LIBRADOS_CMPXATTR_OP_EQ,
   LIBRADOS_CMPXATTR_OP_LT, or LIBRADOS_CMPXATTR_OP_GT
 * @param val value to compare with
 * @param val_len length of value in bytes
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_write_op_omap_cmp(rados_write_op_t write_op,
                                            const char *key,
                                            uint8_t comparison_operator,
                                            const char *val,
                                            size_t val_len,
                                            int *prval);

/**
 * Ensure that the an omap value satisfies a comparison,
 * with the supplied value on the right hand side (i.e.
 * for OP_LT, the comparison is actual_value < value.
 *
 * @param write_op operation to add this action to
 * @param key which omap value to compare
 * @param comparison_operator one of LIBRADOS_CMPXATTR_OP_EQ,
   LIBRADOS_CMPXATTR_OP_LT, or LIBRADOS_CMPXATTR_OP_GT
 * @param val value to compare with
 * @param key_len length of key in bytes
 * @param val_len length of value in bytes
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_write_op_omap_cmp2(rados_write_op_t write_op,
                                            const char *key,
                                            uint8_t comparison_operator,
                                            const char *val,
                                            size_t key_len,
                                            size_t val_len,
                                            int *prval);

/**
 * Set an xattr
 * @param write_op operation to add this action to
 * @param name name of the xattr
 * @param value buffer to set xattr to
 * @param value_len length of buffer to set xattr to
 */
CEPH_RADOS_API void rados_write_op_setxattr(rados_write_op_t write_op,
                                            const char *name,
                                            const char *value,
                                            size_t value_len);

/**
 * Remove an xattr
 * @param write_op operation to add this action to
 * @param name name of the xattr to remove
 */
CEPH_RADOS_API void rados_write_op_rmxattr(rados_write_op_t write_op,
                                           const char *name);

/**
 * Create the object
 * @param write_op operation to add this action to
 * @param exclusive set to either LIBRADOS_CREATE_EXCLUSIVE or
   LIBRADOS_CREATE_IDEMPOTENT
 * will error if the object already exists.
 * @param category category string (DEPRECATED, HAS NO EFFECT)
 */
CEPH_RADOS_API void rados_write_op_create(rados_write_op_t write_op,
                                          int exclusive,
                                          const char* category);

/**
 * Write to offset
 * @param write_op operation to add this action to
 * @param offset offset to write to
 * @param buffer bytes to write
 * @param len length of buffer
 */
CEPH_RADOS_API void rados_write_op_write(rados_write_op_t write_op,
                                         const char *buffer,
                                         size_t len,
                                         uint64_t offset);

/**
 * Write whole object, atomically replacing it.
 * @param write_op operation to add this action to
 * @param buffer bytes to write
 * @param len length of buffer
 */
CEPH_RADOS_API void rados_write_op_write_full(rados_write_op_t write_op,
                                              const char *buffer,
                                              size_t len);

/**
 * Write the same buffer multiple times
 * @param write_op operation to add this action to
 * @param buffer bytes to write
 * @param data_len length of buffer
 * @param write_len total number of bytes to write, as a multiple of @c data_len
 * @param offset offset to write to
 */
CEPH_RADOS_API void rados_write_op_writesame(rados_write_op_t write_op,
                                             const char *buffer,
                                             size_t data_len,
                                             size_t write_len,
                                             uint64_t offset);

/**
 * Append to end of object.
 * @param write_op operation to add this action to
 * @param buffer bytes to write
 * @param len length of buffer
 */
CEPH_RADOS_API void rados_write_op_append(rados_write_op_t write_op,
                                          const char *buffer,
                                          size_t len);
/**
 * Remove object
 * @param write_op operation to add this action to
 */
CEPH_RADOS_API void rados_write_op_remove(rados_write_op_t write_op);

/**
 * Truncate an object
 * @param write_op operation to add this action to
 * @param offset Offset to truncate to
 */
CEPH_RADOS_API void rados_write_op_truncate(rados_write_op_t write_op,
                                            uint64_t offset);

/**
 * Zero part of an object
 * @param write_op operation to add this action to
 * @param offset Offset to zero
 * @param len length to zero
 */
CEPH_RADOS_API void rados_write_op_zero(rados_write_op_t write_op,
			                uint64_t offset,
			                uint64_t len);

/**
 * Execute an OSD class method on an object
 * See rados_exec() for general description.
 *
 * @param write_op operation to add this action to
 * @param cls the name of the class
 * @param method the name of the method
 * @param in_buf where to find input
 * @param in_len length of in_buf in bytes
 * @param prval where to store the return value from the method
 */
CEPH_RADOS_API void rados_write_op_exec(rados_write_op_t write_op,
			                const char *cls,
			                const char *method,
			                const char *in_buf,
			                size_t in_len,
			                int *prval);

/**
 * Set key/value pairs on an object
 *
 * @param write_op operation to add this action to
 * @param keys array of null-terminated char arrays representing keys to set
 * @param vals array of pointers to values to set
 * @param lens array of lengths corresponding to each value
 * @param num number of key/value pairs to set
 */
CEPH_RADOS_API void rados_write_op_omap_set(rados_write_op_t write_op,
                                            char const* const* keys,
                                            char const* const* vals,
                                            const size_t *lens,
                                            size_t num);

/**
 * Set key/value pairs on an object
 *
 * @param write_op operation to add this action to
 * @param keys array of null-terminated char arrays representing keys to set
 * @param vals array of pointers to values to set
 * @param key_lens array of lengths corresponding to each key
 * @param val_lens array of lengths corresponding to each value
 * @param num number of key/value pairs to set
 */
CEPH_RADOS_API void rados_write_op_omap_set2(rados_write_op_t write_op,
                                            char const* const* keys,
                                            char const* const* vals,
                                            const size_t *key_lens,
                                            const size_t *val_lens,
                                            size_t num);

/**
 * Remove key/value pairs from an object
 *
 * @param write_op operation to add this action to
 * @param keys array of null-terminated char arrays representing keys to remove
 * @param keys_len number of key/value pairs to remove
 */
CEPH_RADOS_API void rados_write_op_omap_rm_keys(rados_write_op_t write_op,
                                                char const* const* keys,
                                                size_t keys_len);

/**
 * Remove key/value pairs from an object
 *
 * @param write_op operation to add this action to
 * @param keys array of char arrays representing keys to remove
 * @param key_lens array of size_t values representing length of each key
 * @param keys_len number of key/value pairs to remove
 */
CEPH_RADOS_API void rados_write_op_omap_rm_keys2(rados_write_op_t write_op,
                                                char const* const* keys,
                                                const size_t* key_lens,
                                                size_t keys_len);


/**
 * Remove key/value pairs from an object whose keys are in the range
 * [key_begin, key_end)
 *
 * @param write_op operation to add this action to
 * @param key_begin the lower bound of the key range to remove
 * @param key_begin_len length of key_begin
 * @param key_end the upper bound of the key range to remove
 * @param key_end_len length of key_end
 */
CEPH_RADOS_API void rados_write_op_omap_rm_range2(rados_write_op_t write_op,
                                                  const char *key_begin,
                                                  size_t key_begin_len,
                                                  const char *key_end,
                                                  size_t key_end_len);

/**
 * Remove all key/value pairs from an object
 *
 * @param write_op operation to add this action to
 */
CEPH_RADOS_API void rados_write_op_omap_clear(rados_write_op_t write_op);

/**
 * Set allocation hint for an object
 *
 * @param write_op operation to add this action to
 * @param expected_object_size expected size of the object, in bytes
 * @param expected_write_size expected size of writes to the object, in bytes
 */
CEPH_RADOS_API void rados_write_op_set_alloc_hint(rados_write_op_t write_op,
                                                  uint64_t expected_object_size,
                                                  uint64_t expected_write_size);

/**
 * Set allocation hint for an object
 *
 * @param write_op operation to add this action to
 * @param expected_object_size expected size of the object, in bytes
 * @param expected_write_size expected size of writes to the object, in bytes
 * @param flags hints about future IO patterns
 */
CEPH_RADOS_API void rados_write_op_set_alloc_hint2(rados_write_op_t write_op,
						   uint64_t expected_object_size,
						   uint64_t expected_write_size,
						   uint32_t flags);

/**
 * Perform a write operation synchronously
 * @param write_op operation to perform
 * @param io the ioctx that the object is in
 * @param oid the object id
 * @param mtime the time to set the mtime to, NULL for the current time
 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
 */
CEPH_RADOS_API int rados_write_op_operate(rados_write_op_t write_op,
			                  rados_ioctx_t io,
			                  const char *oid,
			                  time_t *mtime,
			                  int flags);
/**
 * Perform a write operation synchronously
 * @param write_op operation to perform
 * @param io the ioctx that the object is in
 * @param oid the object id
 * @param mtime the time to set the mtime to, NULL for the current time
 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
 */

CEPH_RADOS_API int rados_write_op_operate2(rados_write_op_t write_op,
                                           rados_ioctx_t io,
                                           const char *oid,
                                           struct timespec *mtime,
                                           int flags);

/**
 * Perform a write operation asynchronously
 * @param write_op operation to perform
 * @param io the ioctx that the object is in
 * @param completion what to do when operation has been attempted
 * @param oid the object id
 * @param mtime the time to set the mtime to, NULL for the current time
 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
 */
CEPH_RADOS_API int rados_aio_write_op_operate(rados_write_op_t write_op,
                                              rados_ioctx_t io,
                                              rados_completion_t completion,
                                              const char *oid,
                                              time_t *mtime,
			                      int flags);

/**
 * Create a new rados_read_op_t read operation. This will store all
 * actions to be performed atomically. You must call
 * rados_release_read_op when you are finished with it (after it
 * completes, or you decide not to send it in the first place).
 *
 * @note the ownership of a read operartion is passed to the function
 *       performing the operation, so the same instance of @c rados_read_op_t
 *       cannot be used again after being performed.
 *
 * @returns non-NULL on success, NULL on memory allocation error.
 */
CEPH_RADOS_API rados_read_op_t rados_create_read_op(void);

/**
 * Free a rados_read_op_t, must be called when you're done with it.
 * @param read_op operation to deallocate, created with rados_create_read_op
 */
CEPH_RADOS_API void rados_release_read_op(rados_read_op_t read_op);

/**
 * Set flags for the last operation added to this read_op.
 * At least one op must have been added to the read_op.
 * @param read_op operation to add this action to
 * @param flags see librados.h constants beginning with LIBRADOS_OP_FLAG
 */
CEPH_RADOS_API void rados_read_op_set_flags(rados_read_op_t read_op, int flags);

/**
 * Ensure that the object exists before reading
 * @param read_op operation to add this action to
 */
CEPH_RADOS_API void rados_read_op_assert_exists(rados_read_op_t read_op);

/**
 * Ensure that the object exists and that its internal version
 * number is equal to "ver" before reading. "ver" should be a
 * version number previously obtained with rados_get_last_version().
 * - If the object's version is greater than the asserted version
 *   then rados_read_op_operate will return -ERANGE instead of
 *   executing the op.
 * - If the object's version is less than the asserted version
 *   then rados_read_op_operate will return -EOVERFLOW instead
 *   of executing the op.
 * @param read_op operation to add this action to
 * @param ver object version number
 */
CEPH_RADOS_API void rados_read_op_assert_version(rados_read_op_t read_op, uint64_t ver);

/**
 * Ensure that given object range (extent) satisfies comparison.
 *
 * @param read_op operation to add this action to
 * @param cmp_buf buffer containing bytes to be compared with object contents
 * @param cmp_len length to compare and size of @c cmp_buf in bytes
 * @param off object byte offset at which to start the comparison
 * @param prval returned result of comparison, 0 on success, negative error code
 *  on failure, (-MAX_ERRNO - mismatch_off) on mismatch
 */
CEPH_RADOS_API void rados_read_op_cmpext(rados_read_op_t read_op,
                                         const char *cmp_buf,
                                         size_t cmp_len,
                                         uint64_t off,
                                         int *prval);

/**
 * Ensure that the an xattr satisfies a comparison
 * If the comparison is not satisfied, the return code of the
 * operation will be -ECANCELED
 * @param read_op operation to add this action to
 * @param name name of the xattr to look up
 * @param comparison_operator currently undocumented, look for
 * LIBRADOS_CMPXATTR_OP_EQ in librados.h
 * @param value buffer to compare actual xattr value to
 * @param value_len length of buffer to compare actual xattr value to
 */
CEPH_RADOS_API void rados_read_op_cmpxattr(rados_read_op_t read_op,
			                   const char *name,
			                   uint8_t comparison_operator,
			                   const char *value,
			                   size_t value_len);

/**
 * Start iterating over xattrs on an object.
 *
 * @param read_op operation to add this action to
 * @param iter where to store the iterator
 * @param prval where to store the return value of this action
 */
CEPH_RADOS_API void rados_read_op_getxattrs(rados_read_op_t read_op,
			                    rados_xattrs_iter_t *iter,
			                    int *prval);

/**
 * Ensure that the an omap value satisfies a comparison,
 * with the supplied value on the right hand side (i.e.
 * for OP_LT, the comparison is actual_value < value.
 *
 * @param read_op operation to add this action to
 * @param key which omap value to compare
 * @param comparison_operator one of LIBRADOS_CMPXATTR_OP_EQ,
   LIBRADOS_CMPXATTR_OP_LT, or LIBRADOS_CMPXATTR_OP_GT
 * @param val value to compare with
 * @param val_len length of value in bytes
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_read_op_omap_cmp(rados_read_op_t read_op,
                                           const char *key,
                                           uint8_t comparison_operator,
                                           const char *val,
                                           size_t val_len,
                                           int *prval);

/**
 * Ensure that the an omap value satisfies a comparison,
 * with the supplied value on the right hand side (i.e.
 * for OP_LT, the comparison is actual_value < value.
 *
 * @param read_op operation to add this action to
 * @param key which omap value to compare
 * @param comparison_operator one of LIBRADOS_CMPXATTR_OP_EQ,
   LIBRADOS_CMPXATTR_OP_LT, or LIBRADOS_CMPXATTR_OP_GT
 * @param val value to compare with
 * @param key_len length of key in bytes
 * @param val_len length of value in bytes
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_read_op_omap_cmp2(rados_read_op_t read_op,
                                           const char *key,
                                           uint8_t comparison_operator,
                                           const char *val,
                                           size_t key_len,
                                           size_t val_len,
                                           int *prval);

/**
 * Get object size and mtime
 * @param read_op operation to add this action to
 * @param psize where to store object size
 * @param pmtime where to store modification time
 * @param prval where to store the return value of this action
 */
CEPH_RADOS_API void rados_read_op_stat(rados_read_op_t read_op,
			               uint64_t *psize,
			               time_t *pmtime,
			               int *prval);

/**
 * Read bytes from offset into buffer.
 *
 * prlen will be filled with the number of bytes read if successful.
 * A short read can only occur if the read reaches the end of the
 * object.
 *
 * @param read_op operation to add this action to
 * @param offset offset to read from
 * @param len length of buffer
 * @param buffer where to put the data
 * @param bytes_read where to store the number of bytes read by this action
 * @param prval where to store the return value of this action
 */
CEPH_RADOS_API void rados_read_op_read(rados_read_op_t read_op,
			               uint64_t offset,
			               size_t len,
			               char *buffer,
			               size_t *bytes_read,
			               int *prval);

/**
 * Compute checksum from object data
 *
 * @param read_op operation to add this action to
 * @param type the checksum algorithm to utilize
 * @param init_value the init value for the algorithm
 * @param init_value_len the length of the init value
 * @param offset the offset to start checksumming in the object
 * @param len the number of bytes to checksum
 * @param chunk_size optional length-aligned chunk size for checksums
 * @param pchecksum where to store the checksum result for this action
 * @param checksum_len the number of bytes available for the result
 * @param prval where to store the return value for this action
 */
CEPH_RADOS_API void rados_read_op_checksum(rados_read_op_t read_op,
					   rados_checksum_type_t type,
					   const char *init_value,
					   size_t init_value_len,
					   uint64_t offset, size_t len,
					   size_t chunk_size, char *pchecksum,
					   size_t checksum_len, int *prval);

/**
 * Execute an OSD class method on an object
 * See rados_exec() for general description.
 *
 * The output buffer is allocated on the heap; the caller is
 * expected to release that memory with rados_buffer_free(). The
 * buffer and length pointers can all be NULL, in which case they are
 * not filled in.
 *
 * @param read_op operation to add this action to
 * @param cls the name of the class
 * @param method the name of the method
 * @param in_buf where to find input
 * @param in_len length of in_buf in bytes
 * @param out_buf where to put librados-allocated output buffer
 * @param out_len length of out_buf in bytes
 * @param prval where to store the return value from the method
 */
CEPH_RADOS_API void rados_read_op_exec(rados_read_op_t read_op,
			               const char *cls,
			               const char *method,
			               const char *in_buf,
			               size_t in_len,
			               char **out_buf,
			               size_t *out_len,
			               int *prval);

/**
 * Execute an OSD class method on an object
 * See rados_exec() for general description.
 *
 * If the output buffer is too small, prval will
 * be set to -ERANGE and used_len will be 0.
 *
 * @param read_op operation to add this action to
 * @param cls the name of the class
 * @param method the name of the method
 * @param in_buf where to find input
 * @param in_len length of in_buf in bytes
 * @param out_buf user-provided buffer to read into
 * @param out_len length of out_buf in bytes
 * @param used_len where to store the number of bytes read into out_buf
 * @param prval where to store the return value from the method
 */
CEPH_RADOS_API void rados_read_op_exec_user_buf(rados_read_op_t read_op,
				                const char *cls,
				                const char *method,
				                const char *in_buf,
				                size_t in_len,
				                char *out_buf,
				                size_t out_len,
				                size_t *used_len,
				                int *prval);

/**
 * Start iterating over key/value pairs on an object.
 *
 * They will be returned sorted by key.
 *
 * @param read_op operation to add this action to
 * @param start_after list keys starting after start_after
 * @param filter_prefix list only keys beginning with filter_prefix
 * @param max_return list no more than max_return key/value pairs
 * @param iter where to store the iterator
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_read_op_omap_get_vals(rados_read_op_t read_op,
				                const char *start_after,
				                const char *filter_prefix,
				                uint64_t max_return,
				                rados_omap_iter_t *iter,
				                int *prval)
  __attribute__((deprecated)); /* use v2 below */

/**
 * Start iterating over key/value pairs on an object.
 *
 * They will be returned sorted by key.
 *
 * @param read_op operation to add this action to
 * @param start_after list keys starting after start_after
 * @param filter_prefix list only keys beginning with filter_prefix
 * @param max_return list no more than max_return key/value pairs
 * @param iter where to store the iterator
 * @param pmore flag indicating whether there are more keys to fetch
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_read_op_omap_get_vals2(rados_read_op_t read_op,
						 const char *start_after,
						 const char *filter_prefix,
						 uint64_t max_return,
						 rados_omap_iter_t *iter,
						 unsigned char *pmore,
						 int *prval);

/**
 * Start iterating over keys on an object.
 *
 * They will be returned sorted by key, and the iterator
 * will fill in NULL for all values if specified.
 *
 * @param read_op operation to add this action to
 * @param start_after list keys starting after start_after
 * @param max_return list no more than max_return keys
 * @param iter where to store the iterator
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_read_op_omap_get_keys(rados_read_op_t read_op,
				                const char *start_after,
				                uint64_t max_return,
				                rados_omap_iter_t *iter,
				                int *prval)
  __attribute__((deprecated)); /* use v2 below */

/**
 * Start iterating over keys on an object.
 *
 * They will be returned sorted by key, and the iterator
 * will fill in NULL for all values if specified.
 *
 * @param read_op operation to add this action to
 * @param start_after list keys starting after start_after
 * @param max_return list no more than max_return keys
 * @param iter where to store the iterator
 * @param pmore flag indicating whether there are more keys to fetch
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_read_op_omap_get_keys2(rados_read_op_t read_op,
						 const char *start_after,
						 uint64_t max_return,
						 rados_omap_iter_t *iter,
						 unsigned char *pmore,
						 int *prval);

/**
 * Start iterating over specific key/value pairs
 *
 * They will be returned sorted by key.
 *
 * @param read_op operation to add this action to
 * @param keys array of pointers to null-terminated keys to get
 * @param keys_len the number of strings in keys
 * @param iter where to store the iterator
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_read_op_omap_get_vals_by_keys(rados_read_op_t read_op,
                                                        char const* const* keys,
                                                        size_t keys_len,
                                                        rados_omap_iter_t *iter,
                                                        int *prval);

/**
 * Start iterating over specific key/value pairs
 *
 * They will be returned sorted by key.
 *
 * @param read_op operation to add this action to
 * @param keys array of pointers to keys to get
 * @param num_keys the number of strings in keys
 * @param key_lens array of size_t's describing each key len (in bytes)
 * @param iter where to store the iterator
 * @param prval where to store the return value from this action
 */
CEPH_RADOS_API void rados_read_op_omap_get_vals_by_keys2(rados_read_op_t read_op,
                                                        char const* const* keys,
                                                        size_t num_keys,
                                                        const size_t* key_lens,
                                                        rados_omap_iter_t *iter,
                                                        int *prval);

/**
 * Perform a read operation synchronously
 * @param read_op operation to perform
 * @param io the ioctx that the object is in
 * @param oid the object id
 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
 */
CEPH_RADOS_API int rados_read_op_operate(rados_read_op_t read_op,
			                 rados_ioctx_t io,
			                 const char *oid,
			                 int flags);

/**
 * Perform a read operation asynchronously
 * @param read_op operation to perform
 * @param io the ioctx that the object is in
 * @param completion what to do when operation has been attempted
 * @param oid the object id
 * @param flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
 */
CEPH_RADOS_API int rados_aio_read_op_operate(rados_read_op_t read_op,
			                     rados_ioctx_t io,
			                     rados_completion_t completion,
			                     const char *oid,
			                     int flags);

/** @} Object Operations */

/**
 * Take an exclusive lock on an object.
 *
 * @param io the context to operate in
 * @param oid the name of the object
 * @param name the name of the lock
 * @param cookie user-defined identifier for this instance of the lock
 * @param desc user-defined lock description
 * @param duration the duration of the lock. Set to NULL for infinite duration.
 * @param flags lock flags
 * @returns 0 on success, negative error code on failure
 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
 */
CEPH_RADOS_API int rados_lock_exclusive(rados_ioctx_t io, const char * oid,
                                        const char * name, const char * cookie,
                                        const char * desc,
                                        struct timeval * duration,
                                        uint8_t flags);

/**
 * Take a shared lock on an object.
 *
 * @param io the context to operate in
 * @param o the name of the object
 * @param name the name of the lock
 * @param cookie user-defined identifier for this instance of the lock
 * @param tag The tag of the lock
 * @param desc user-defined lock description
 * @param duration the duration of the lock. Set to NULL for infinite duration.
 * @param flags lock flags
 * @returns 0 on success, negative error code on failure
 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
 */
CEPH_RADOS_API int rados_lock_shared(rados_ioctx_t io, const char * o,
                                     const char * name, const char * cookie,
                                     const char * tag, const char * desc,
	                             struct timeval * duration, uint8_t flags);

/**
 * Release a shared or exclusive lock on an object.
 *
 * @param io the context to operate in
 * @param o the name of the object
 * @param name the name of the lock
 * @param cookie user-defined identifier for the instance of the lock
 * @returns 0 on success, negative error code on failure
 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
 */
CEPH_RADOS_API int rados_unlock(rados_ioctx_t io, const char *o,
                                const char *name, const char *cookie);

/**
 * Asynchronous release a shared or exclusive lock on an object.
 *
 * @param io the context to operate in
 * @param o the name of the object
 * @param name the name of the lock
 * @param cookie user-defined identifier for the instance of the lock
 * @param completion what to do when operation has been attempted
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_aio_unlock(rados_ioctx_t io, const char *o,
                                    const char *name, const char *cookie,
			            rados_completion_t completion);

/**
 * List clients that have locked the named object lock and information about
 * the lock.
 *
 * The number of bytes required in each buffer is put in the
 * corresponding size out parameter. If any of the provided buffers
 * are too short, -ERANGE is returned after these sizes are filled in.
 *
 * @param io the context to operate in
 * @param o the name of the object
 * @param name the name of the lock
 * @param exclusive where to store whether the lock is exclusive (1) or shared (0)
 * @param tag where to store the tag associated with the object lock
 * @param tag_len number of bytes in tag buffer
 * @param clients buffer in which locker clients are stored, separated by '\0'
 * @param clients_len number of bytes in the clients buffer
 * @param cookies buffer in which locker cookies are stored, separated by '\0'
 * @param cookies_len number of bytes in the cookies buffer
 * @param addrs buffer in which locker addresses are stored, separated by '\0'
 * @param addrs_len number of bytes in the clients buffer
 * @returns number of lockers on success, negative error code on failure
 * @returns -ERANGE if any of the buffers are too short
 */
CEPH_RADOS_API ssize_t rados_list_lockers(rados_ioctx_t io, const char *o,
			                  const char *name, int *exclusive,
			                  char *tag, size_t *tag_len,
			                  char *clients, size_t *clients_len,
			                  char *cookies, size_t *cookies_len,
			                  char *addrs, size_t *addrs_len);

/**
 * Releases a shared or exclusive lock on an object, which was taken by the
 * specified client.
 *
 * @param io the context to operate in
 * @param o the name of the object
 * @param name the name of the lock
 * @param client the client currently holding the lock
 * @param cookie user-defined identifier for the instance of the lock
 * @returns 0 on success, negative error code on failure
 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
 * @returns -EINVAL if the client cannot be parsed
 */
CEPH_RADOS_API int rados_break_lock(rados_ioctx_t io, const char *o,
                                    const char *name, const char *client,
                                    const char *cookie);

/**
 * Blocklists the specified client from the OSDs
 *
 * @param cluster cluster handle
 * @param client_address client address
 * @param expire_seconds number of seconds to blocklist (0 for default)
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_blocklist_add(rados_t cluster,
				       char *client_address,
				       uint32_t expire_seconds);
CEPH_RADOS_API int rados_blacklist_add(rados_t cluster,
				       char *client_address,
				       uint32_t expire_seconds)
  __attribute__((deprecated));

/**
 * Gets addresses of the RADOS session, suitable for blocklisting.
 *
 * @param cluster cluster handle
 * @param addrs the output string.
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_getaddrs(rados_t cluster, char** addrs);

CEPH_RADOS_API void rados_set_osdmap_full_try(rados_ioctx_t io)
  __attribute__((deprecated));

CEPH_RADOS_API void rados_unset_osdmap_full_try(rados_ioctx_t io)
  __attribute__((deprecated));

CEPH_RADOS_API void rados_set_pool_full_try(rados_ioctx_t io);

CEPH_RADOS_API void rados_unset_pool_full_try(rados_ioctx_t io);

/**
 * Enable an application on a pool
 *
 * @param io pool ioctx
 * @param app_name application name
 * @param force 0 if only single application per pool
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_application_enable(rados_ioctx_t io,
                                            const char *app_name, int force);

/**
 * List all enabled applications
 *
 * If the provided buffer is too short, the required length is filled in and
 * -ERANGE is returned. Otherwise, the buffers are filled with the application
 * names, with a '\0' after each.
 *
 * @param io pool ioctx
 * @param values buffer in which to store application names
 * @param values_len number of bytes in values buffer
 * @returns 0 on success, negative error code on failure
 * @returns -ERANGE if either buffer is too short
 */
CEPH_RADOS_API int rados_application_list(rados_ioctx_t io, char *values,
                                          size_t *values_len);

/**
 * Get application metadata value from pool
 *
 * @param io pool ioctx
 * @param app_name application name
 * @param key metadata key
 * @param value result buffer
 * @param value_len maximum len of value
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_application_metadata_get(rados_ioctx_t io,
                                                  const char *app_name,
                                                  const char *key, char *value,
                                                  size_t *value_len);

/**
 * Set application metadata on a pool
 *
 * @param io pool ioctx
 * @param app_name application name
 * @param key metadata key
 * @param value metadata key
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_application_metadata_set(rados_ioctx_t io,
                                                  const char *app_name,
                                                  const char *key,
                                                  const char *value);

/**
 * Remove application metadata from a pool
 *
 * @param io pool ioctx
 * @param app_name application name
 * @param key metadata key
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_application_metadata_remove(rados_ioctx_t io,
                                                     const char *app_name,
                                                     const char *key);

/**
 * List all metadata key/value pairs associated with an application.
 *
 * This iterates over all metadata, key_len and val_len are filled in
 * with the number of bytes put into the keys and values buffers.
 *
 * If the provided buffers are too short, the required lengths are filled
 * in and -ERANGE is returned. Otherwise, the buffers are filled with
 * the keys and values of the metadata, with a '\0' after each.
 *
 * @param io pool ioctx
 * @param app_name application name
 * @param keys buffer in which to store key names
 * @param key_len number of bytes in keys buffer
 * @param values buffer in which to store values
 * @param vals_len number of bytes in values buffer
 * @returns 0 on success, negative error code on failure
 * @returns -ERANGE if either buffer is too short
 */
CEPH_RADOS_API int rados_application_metadata_list(rados_ioctx_t io,
                                                   const char *app_name,
                                                   char *keys, size_t *key_len,
                                                   char *values,
                                                   size_t *vals_len);

/**
 * @name Mon/OSD/PG Commands
 *
 * These interfaces send commands relating to the monitor, OSD, or PGs.
 *
 * @{
 */

/**
 * Send monitor command.
 *
 * @note Takes command string in carefully-formatted JSON; must match
 * defined commands, types, etc.
 *
 * The result buffers are allocated on the heap; the caller is
 * expected to release that memory with rados_buffer_free().  The
 * buffer and length pointers can all be NULL, in which case they are
 * not filled in.
 *
 * @param cluster cluster handle
 * @param cmd an array of char *'s representing the command
 * @param cmdlen count of valid entries in cmd
 * @param inbuf any bulk input data (crush map, etc.)
 * @param inbuflen input buffer length
 * @param outbuf double pointer to output buffer
 * @param outbuflen pointer to output buffer length
 * @param outs double pointer to status string
 * @param outslen pointer to status string length
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_mon_command(rados_t cluster, const char **cmd,
                                     size_t cmdlen, const char *inbuf,
                                     size_t inbuflen, char **outbuf,
                                     size_t *outbuflen, char **outs,
                                     size_t *outslen);

/**
 * Send ceph-mgr command.
 *
 * @note Takes command string in carefully-formatted JSON; must match
 * defined commands, types, etc.
 *
 * The result buffers are allocated on the heap; the caller is
 * expected to release that memory with rados_buffer_free().  The
 * buffer and length pointers can all be NULL, in which case they are
 * not filled in.
 *
 * @param cluster cluster handle
 * @param cmd an array of char *'s representing the command
 * @param cmdlen count of valid entries in cmd
 * @param inbuf any bulk input data (crush map, etc.)
 * @param inbuflen input buffer length
 * @param outbuf double pointer to output buffer
 * @param outbuflen pointer to output buffer length
 * @param outs double pointer to status string
 * @param outslen pointer to status string length
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_mgr_command(rados_t cluster, const char **cmd,
                                     size_t cmdlen, const char *inbuf,
                                     size_t inbuflen, char **outbuf,
                                     size_t *outbuflen, char **outs,
                                     size_t *outslen);

/**
 * Send ceph-mgr tell command.
 *
 * @note Takes command string in carefully-formatted JSON; must match
 * defined commands, types, etc.
 *
 * The result buffers are allocated on the heap; the caller is
 * expected to release that memory with rados_buffer_free().  The
 * buffer and length pointers can all be NULL, in which case they are
 * not filled in.
 *
 * @param cluster cluster handle
 * @param name mgr name to target
 * @param cmd an array of char *'s representing the command
 * @param cmdlen count of valid entries in cmd
 * @param inbuf any bulk input data (crush map, etc.)
 * @param inbuflen input buffer length
 * @param outbuf double pointer to output buffer
 * @param outbuflen pointer to output buffer length
 * @param outs double pointer to status string
 * @param outslen pointer to status string length
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_mgr_command_target(
  rados_t cluster,
  const char *name,
  const char **cmd,
  size_t cmdlen, const char *inbuf,
  size_t inbuflen, char **outbuf,
  size_t *outbuflen, char **outs,
  size_t *outslen);

/**
 * Send monitor command to a specific monitor.
 *
 * @note Takes command string in carefully-formatted JSON; must match
 * defined commands, types, etc.
 *
 * The result buffers are allocated on the heap; the caller is
 * expected to release that memory with rados_buffer_free().  The
 * buffer and length pointers can all be NULL, in which case they are
 * not filled in.
 *
 * @param cluster cluster handle
 * @param name target monitor's name
 * @param cmd an array of char *'s representing the command
 * @param cmdlen count of valid entries in cmd
 * @param inbuf any bulk input data (crush map, etc.)
 * @param inbuflen input buffer length
 * @param outbuf double pointer to output buffer
 * @param outbuflen pointer to output buffer length
 * @param outs double pointer to status string
 * @param outslen pointer to status string length
 * @returns 0 on success, negative error code on failure
 */
CEPH_RADOS_API int rados_mon_command_target(rados_t cluster, const char *name,
			                    const char **cmd, size_t cmdlen,
			                    const char *inbuf, size_t inbuflen,
			                    char **outbuf, size_t *outbuflen,
			                    char **outs, size_t *outslen);

/**
 * free a rados-allocated buffer
 *
 * Release memory allocated by librados calls like rados_mon_command().
 *
 * @param buf buffer pointer
 */
CEPH_RADOS_API void rados_buffer_free(char *buf);

CEPH_RADOS_API int rados_osd_command(rados_t cluster, int osdid,
                                     const char **cmd, size_t cmdlen,
		                     const char *inbuf, size_t inbuflen,
		                     char **outbuf, size_t *outbuflen,
		                     char **outs, size_t *outslen);

CEPH_RADOS_API int rados_pg_command(rados_t cluster, const char *pgstr,
                                    const char **cmd, size_t cmdlen,
		                    const char *inbuf, size_t inbuflen,
		                    char **outbuf, size_t *outbuflen,
		                    char **outs, size_t *outslen);

CEPH_RADOS_API int rados_mgr_command(rados_t cluster,
                                     const char **cmd, size_t cmdlen,
		                     const char *inbuf, size_t inbuflen,
		                     char **outbuf, size_t *outbuflen,
		                     char **outs, size_t *outslen);

/*
 * This is not a doxygen comment leadin, because doxygen breaks on
 * a typedef with function params and returns, and I can't figure out
 * how to fix it.
 *
 * Monitor cluster log
 *
 * Monitor events logged to the cluster log.  The callback get each
 * log entry both as a single formatted line and with each field in a
 * separate arg.
 *
 * Calling with a cb argument of NULL will deregister any previously
 * registered callback.
 *
 * @param cluster cluster handle
 * @param level minimum log level (debug, info, warn|warning, err|error)
 * @param cb callback to run for each log message. It MUST NOT block
 * nor call back into librados.
 * @param arg void argument to pass to cb
 *
 * @returns 0 on success, negative code on error
 */
typedef void (*rados_log_callback_t)(void *arg,
				     const char *line,
				     const char *who, 
				     uint64_t sec, uint64_t nsec,
				     uint64_t seq, const char *level,
				     const char *msg);

/*
 * This is not a doxygen comment leadin, because doxygen breaks on
 * a typedef with function params and returns, and I can't figure out
 * how to fix it.
 *
 * Monitor cluster log
 *
 * Monitor events logged to the cluster log.  The callback get each
 * log entry both as a single formatted line and with each field in a
 * separate arg.
 *
 * Calling with a cb argument of NULL will deregister any previously
 * registered callback.
 *
 * @param cluster cluster handle
 * @param level minimum log level (debug, info, warn|warning, err|error)
 * @param cb callback to run for each log message. It MUST NOT block
 * nor call back into librados.
 * @param arg void argument to pass to cb
 *
 * @returns 0 on success, negative code on error
 */
typedef void (*rados_log_callback2_t)(void *arg,
				     const char *line,
				     const char *channel,
				     const char *who,
				     const char *name,
				     uint64_t sec, uint64_t nsec,
				     uint64_t seq, const char *level,
				     const char *msg);

CEPH_RADOS_API int rados_monitor_log(rados_t cluster, const char *level,
                                     rados_log_callback_t cb, void *arg);
CEPH_RADOS_API int rados_monitor_log2(rados_t cluster, const char *level,
				      rados_log_callback2_t cb, void *arg);


/**
 * register daemon instance for a service
 *
 * Register us as a daemon providing a particular service.  We identify
 * the service (e.g., 'rgw') and our instance name (e.g., 'rgw.$hostname').
 * The metadata is a map of keys and values with arbitrary static metdata
 * for this instance.  The encoding is a series of NULL-terminated strings,
 * alternating key names and values, terminating with an empty key name.
 * For example,  "foo\0bar\0this\0that\0\0" is the dict {foo=bar,this=that}.
 *
 * For the lifetime of the librados instance, regular beacons will be sent
 * to the cluster to maintain our registration in the service map.
 *
 * @param cluster handle
 * @param service service name
 * @param daemon daemon instance name
 * @param metadata_dict static daemon metadata dict
 */
CEPH_RADOS_API int rados_service_register(
  rados_t cluster,
  const char *service,
  const char *daemon,
  const char *metadata_dict);

/**
 * update daemon status
 *
 * Update our mutable status information in the service map.
 *
 * The status dict is encoded the same way the daemon metadata is encoded
 * for rados_service_register.  For example, "foo\0bar\0this\0that\0\0" is
 * {foo=bar,this=that}.
 *
 * @param cluster rados cluster handle
 * @param status_dict status dict
 */
CEPH_RADOS_API int rados_service_update_status(
  rados_t cluster,
  const char *status_dict);

/** @} Mon/OSD/PG commands */

/*
 * These methods are no longer supported and return -ENOTSUP where possible.
 */
CEPH_RADOS_API int rados_objects_list_open(
  rados_ioctx_t io,
  rados_list_ctx_t *ctx) __attribute__((deprecated));
CEPH_RADOS_API uint32_t rados_objects_list_get_pg_hash_position(
  rados_list_ctx_t ctx) __attribute__((deprecated));
CEPH_RADOS_API uint32_t rados_objects_list_seek(
  rados_list_ctx_t ctx,
  uint32_t pos) __attribute__((deprecated));
CEPH_RADOS_API int rados_objects_list_next(
  rados_list_ctx_t ctx,
  const char **entry,
  const char **key) __attribute__((deprecated));
CEPH_RADOS_API void rados_objects_list_close(
  rados_list_ctx_t ctx) __attribute__((deprecated));


#ifdef __cplusplus
}
#endif

#endif