]> git.proxmox.com Git - ceph.git/blame - ceph/src/include/rbd/librbd.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / include / rbd / librbd.h
CommitLineData
11fdf7f2 1// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
7c673cae
FG
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#ifndef CEPH_LIBRBD_H
16#define CEPH_LIBRBD_H
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <netinet/in.h>
23#if defined(__linux__)
24#include <linux/types.h>
25#elif defined(__FreeBSD__)
26#include <sys/types.h>
27#endif
28#include <stdbool.h>
29#include <string.h>
30#include <sys/uio.h>
31#include "../rados/librados.h"
32#include "features.h"
33
34#define LIBRBD_VER_MAJOR 1
9f95a23c 35#define LIBRBD_VER_MINOR 15
7c673cae
FG
36#define LIBRBD_VER_EXTRA 0
37
38#define LIBRBD_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
39
40#define LIBRBD_VERSION_CODE LIBRBD_VERSION(LIBRBD_VER_MAJOR, LIBRBD_VER_MINOR, LIBRBD_VER_EXTRA)
41
42#define LIBRBD_SUPPORTS_AIO_FLUSH 1
43#define LIBRBD_SUPPORTS_AIO_OPEN 1
b32b8144 44#define LIBRBD_SUPPORTS_COMPARE_AND_WRITE 1
7c673cae
FG
45#define LIBRBD_SUPPORTS_LOCKING 1
46#define LIBRBD_SUPPORTS_INVALIDATE 1
47#define LIBRBD_SUPPORTS_IOVEC 1
48#define LIBRBD_SUPPORTS_WATCH 0
c07f9fc5 49#define LIBRBD_SUPPORTS_WRITESAME 1
7c673cae
FG
50
51#if __GNUC__ >= 4
9f95a23c
TL
52 #define CEPH_RBD_API __attribute__ ((visibility ("default")))
53 #define CEPH_RBD_DEPRECATED __attribute__((deprecated))
54 #pragma GCC diagnostic push
55 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
7c673cae
FG
56#else
57 #define CEPH_RBD_API
9f95a23c 58 #define CEPH_RBD_DEPRECATED
7c673cae
FG
59#endif
60
61#define RBD_FLAG_OBJECT_MAP_INVALID (1<<0)
62#define RBD_FLAG_FAST_DIFF_INVALID (1<<1)
63
9f95a23c
TL
64#define RBD_MIRROR_IMAGE_STATUS_LOCAL_MIRROR_UUID ""
65
7c673cae
FG
66typedef void *rbd_image_t;
67typedef void *rbd_image_options_t;
11fdf7f2 68typedef void *rbd_pool_stats_t;
7c673cae
FG
69
70typedef void *rbd_completion_t;
71typedef void (*rbd_callback_t)(rbd_completion_t cb, void *arg);
72
73typedef int (*librbd_progress_fn_t)(uint64_t offset, uint64_t total, void *ptr);
74
75typedef void (*rbd_update_callback_t)(void *arg);
76
11fdf7f2 77typedef enum {
9f95a23c
TL
78 RBD_SNAP_NAMESPACE_TYPE_USER = 0,
79 RBD_SNAP_NAMESPACE_TYPE_GROUP = 1,
80 RBD_SNAP_NAMESPACE_TYPE_TRASH = 2,
81 RBD_SNAP_NAMESPACE_TYPE_MIRROR = 3,
11fdf7f2
TL
82} rbd_snap_namespace_type_t;
83
84typedef struct {
85 char *id;
86 char *name;
87} rbd_image_spec_t;
88
89typedef struct {
90 int64_t pool_id;
91 char *pool_name;
92 char *pool_namespace;
93 char *image_id;
94 char *image_name;
95 bool trash;
96} rbd_linked_image_spec_t;
97
98typedef struct {
99 uint64_t id;
100 rbd_snap_namespace_type_t namespace_type;
101 char *name;
102} rbd_snap_spec_t;
103
7c673cae
FG
104typedef struct {
105 uint64_t id;
106 uint64_t size;
107 const char *name;
108} rbd_snap_info_t;
109
11fdf7f2
TL
110typedef struct {
111 const char *pool_name;
112 const char *image_name;
113 const char *image_id;
114 bool trash;
115} rbd_child_info_t;
116
7c673cae
FG
117#define RBD_MAX_IMAGE_NAME_SIZE 96
118#define RBD_MAX_BLOCK_NAME_SIZE 24
119
120#define RBD_SNAP_REMOVE_UNPROTECT 1 << 0
121#define RBD_SNAP_REMOVE_FLATTEN 1 << 1
122#define RBD_SNAP_REMOVE_FORCE (RBD_SNAP_REMOVE_UNPROTECT | RBD_SNAP_REMOVE_FLATTEN)
123
124/**
125 * These types used to in set_image_notification to indicate the type of event
126 * socket passed in.
127 */
128enum {
129 EVENT_TYPE_PIPE = 1,
130 EVENT_TYPE_EVENTFD = 2
131};
132
133typedef struct {
134 uint64_t size;
135 uint64_t obj_size;
136 uint64_t num_objs;
137 int order;
138 char block_name_prefix[RBD_MAX_BLOCK_NAME_SIZE]; /* deprecated */
9f95a23c 139 int64_t parent_pool; /* deprecated */
7c673cae
FG
140 char parent_name[RBD_MAX_IMAGE_NAME_SIZE]; /* deprecated */
141} rbd_image_info_t;
142
143typedef enum {
144 RBD_MIRROR_MODE_DISABLED, /* mirroring is disabled */
145 RBD_MIRROR_MODE_IMAGE, /* mirroring enabled on a per-image basis */
146 RBD_MIRROR_MODE_POOL /* mirroring enabled on all journaled images */
147} rbd_mirror_mode_t;
148
eafe8130
TL
149typedef enum {
150 RBD_MIRROR_PEER_DIRECTION_RX = 0,
151 RBD_MIRROR_PEER_DIRECTION_TX = 1,
152 RBD_MIRROR_PEER_DIRECTION_RX_TX = 2
153} rbd_mirror_peer_direction_t;
154
7c673cae
FG
155typedef struct {
156 char *uuid;
157 char *cluster_name;
158 char *client_name;
9f95a23c
TL
159} rbd_mirror_peer_t CEPH_RBD_DEPRECATED;
160
161typedef struct {
162 char *uuid;
163 rbd_mirror_peer_direction_t direction;
164 char *site_name;
165 char *mirror_uuid;
166 char *client_name;
167 time_t last_seen;
168} rbd_mirror_peer_site_t;
7c673cae 169
11fdf7f2
TL
170#define RBD_MIRROR_PEER_ATTRIBUTE_NAME_MON_HOST "mon_host"
171#define RBD_MIRROR_PEER_ATTRIBUTE_NAME_KEY "key"
172
9f95a23c
TL
173typedef enum {
174 RBD_MIRROR_IMAGE_MODE_JOURNAL = 0,
175 RBD_MIRROR_IMAGE_MODE_SNAPSHOT = 1,
176} rbd_mirror_image_mode_t;
177
7c673cae
FG
178typedef enum {
179 RBD_MIRROR_IMAGE_DISABLING = 0,
180 RBD_MIRROR_IMAGE_ENABLED = 1,
181 RBD_MIRROR_IMAGE_DISABLED = 2
182} rbd_mirror_image_state_t;
183
184typedef struct {
185 char *global_id;
186 rbd_mirror_image_state_t state;
187 bool primary;
188} rbd_mirror_image_info_t;
189
190typedef enum {
191 MIRROR_IMAGE_STATUS_STATE_UNKNOWN = 0,
192 MIRROR_IMAGE_STATUS_STATE_ERROR = 1,
193 MIRROR_IMAGE_STATUS_STATE_SYNCING = 2,
194 MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY = 3,
195 MIRROR_IMAGE_STATUS_STATE_REPLAYING = 4,
196 MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY = 5,
197 MIRROR_IMAGE_STATUS_STATE_STOPPED = 6,
198} rbd_mirror_image_status_state_t;
199
200typedef struct {
201 char *name;
202 rbd_mirror_image_info_t info;
203 rbd_mirror_image_status_state_t state;
204 char *description;
205 time_t last_update;
206 bool up;
9f95a23c
TL
207} rbd_mirror_image_status_t CEPH_RBD_DEPRECATED;
208
209typedef struct {
210 char *mirror_uuid;
211 rbd_mirror_image_status_state_t state;
212 char *description;
213 time_t last_update;
214 bool up;
215} rbd_mirror_image_site_status_t;
216
217typedef struct {
218 char *name;
219 rbd_mirror_image_info_t info;
220 uint32_t site_statuses_count;
221 rbd_mirror_image_site_status_t *site_statuses;
222} rbd_mirror_image_global_status_t;
7c673cae 223
11fdf7f2
TL
224typedef enum {
225 RBD_GROUP_IMAGE_STATE_ATTACHED,
226 RBD_GROUP_IMAGE_STATE_INCOMPLETE
227} rbd_group_image_state_t;
228
229typedef struct {
230 char *name;
231 int64_t pool;
232 rbd_group_image_state_t state;
233} rbd_group_image_info_t;
234
235typedef struct {
236 char *name;
237 int64_t pool;
238} rbd_group_info_t;
239
240typedef enum {
241 RBD_GROUP_SNAP_STATE_INCOMPLETE,
242 RBD_GROUP_SNAP_STATE_COMPLETE
243} rbd_group_snap_state_t;
244
245typedef struct {
246 char *name;
247 rbd_group_snap_state_t state;
248} rbd_group_snap_info_t;
249
250typedef struct {
251 int64_t group_pool;
252 char *group_name;
253 char *group_snap_name;
254} rbd_snap_group_namespace_t;
255
9f95a23c
TL
256typedef enum {
257 RBD_SNAP_MIRROR_STATE_PRIMARY,
258 RBD_SNAP_MIRROR_STATE_PRIMARY_DEMOTED,
259 RBD_SNAP_MIRROR_STATE_NON_PRIMARY,
260 RBD_SNAP_MIRROR_STATE_NON_PRIMARY_DEMOTED
261} rbd_snap_mirror_state_t;
262
263typedef struct {
264 rbd_snap_mirror_state_t state;
265 size_t mirror_peer_uuids_count;
266 char *mirror_peer_uuids;
267 bool complete;
268 char *primary_mirror_uuid;
269 uint64_t primary_snap_id;
270 uint64_t last_copied_object_number;
271} rbd_snap_mirror_namespace_t;
272
7c673cae
FG
273typedef enum {
274 RBD_LOCK_MODE_EXCLUSIVE = 0,
275 RBD_LOCK_MODE_SHARED = 1,
276} rbd_lock_mode_t;
277
278CEPH_RBD_API void rbd_version(int *major, int *minor, int *extra);
279
280/* image options */
281enum {
282 RBD_IMAGE_OPTION_FORMAT = 0,
283 RBD_IMAGE_OPTION_FEATURES = 1,
284 RBD_IMAGE_OPTION_ORDER = 2,
285 RBD_IMAGE_OPTION_STRIPE_UNIT = 3,
286 RBD_IMAGE_OPTION_STRIPE_COUNT = 4,
287 RBD_IMAGE_OPTION_JOURNAL_ORDER = 5,
288 RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH = 6,
289 RBD_IMAGE_OPTION_JOURNAL_POOL = 7,
290 RBD_IMAGE_OPTION_FEATURES_SET = 8,
291 RBD_IMAGE_OPTION_FEATURES_CLEAR = 9,
11fdf7f2
TL
292 RBD_IMAGE_OPTION_DATA_POOL = 10,
293 RBD_IMAGE_OPTION_FLATTEN = 11,
92f5a8d4 294 RBD_IMAGE_OPTION_CLONE_FORMAT = 12,
7c673cae
FG
295};
296
297typedef enum {
298 RBD_TRASH_IMAGE_SOURCE_USER = 0,
11fdf7f2
TL
299 RBD_TRASH_IMAGE_SOURCE_MIRRORING = 1,
300 RBD_TRASH_IMAGE_SOURCE_MIGRATION = 2,
9f95a23c
TL
301 RBD_TRASH_IMAGE_SOURCE_REMOVING = 3,
302 RBD_TRASH_IMAGE_SOURCE_USER_PARENT = 4,
7c673cae
FG
303} rbd_trash_image_source_t;
304
305typedef struct {
306 char *id;
307 char *name;
308 rbd_trash_image_source_t source;
309 time_t deletion_time;
310 time_t deferment_end_time;
311} rbd_trash_image_info_t;
312
11fdf7f2
TL
313typedef struct {
314 char *addr;
315 int64_t id;
316 uint64_t cookie;
317} rbd_image_watcher_t;
318
319typedef enum {
320 RBD_IMAGE_MIGRATION_STATE_UNKNOWN = -1,
321 RBD_IMAGE_MIGRATION_STATE_ERROR = 0,
322 RBD_IMAGE_MIGRATION_STATE_PREPARING = 1,
323 RBD_IMAGE_MIGRATION_STATE_PREPARED = 2,
324 RBD_IMAGE_MIGRATION_STATE_EXECUTING = 3,
325 RBD_IMAGE_MIGRATION_STATE_EXECUTED = 4,
326} rbd_image_migration_state_t;
327
328typedef struct {
329 int64_t source_pool_id;
330 char *source_pool_namespace;
331 char *source_image_name;
332 char *source_image_id;
333 int64_t dest_pool_id;
334 char *dest_pool_namespace;
335 char *dest_image_name;
336 char *dest_image_id;
337 rbd_image_migration_state_t state;
338 char *state_description;
339} rbd_image_migration_status_t;
340
341typedef enum {
342 RBD_CONFIG_SOURCE_CONFIG = 0,
343 RBD_CONFIG_SOURCE_POOL = 1,
344 RBD_CONFIG_SOURCE_IMAGE = 2,
345} rbd_config_source_t;
346
347typedef struct {
348 char *name;
349 char *value;
350 rbd_config_source_t source;
351} rbd_config_option_t;
352
353typedef enum {
354 RBD_POOL_STAT_OPTION_IMAGES,
355 RBD_POOL_STAT_OPTION_IMAGE_PROVISIONED_BYTES,
356 RBD_POOL_STAT_OPTION_IMAGE_MAX_PROVISIONED_BYTES,
357 RBD_POOL_STAT_OPTION_IMAGE_SNAPSHOTS,
358 RBD_POOL_STAT_OPTION_TRASH_IMAGES,
359 RBD_POOL_STAT_OPTION_TRASH_PROVISIONED_BYTES,
360 RBD_POOL_STAT_OPTION_TRASH_MAX_PROVISIONED_BYTES,
361 RBD_POOL_STAT_OPTION_TRASH_SNAPSHOTS
362} rbd_pool_stat_option_t;
363
7c673cae
FG
364CEPH_RBD_API void rbd_image_options_create(rbd_image_options_t* opts);
365CEPH_RBD_API void rbd_image_options_destroy(rbd_image_options_t opts);
366CEPH_RBD_API int rbd_image_options_set_string(rbd_image_options_t opts,
367 int optname, const char* optval);
368CEPH_RBD_API int rbd_image_options_set_uint64(rbd_image_options_t opts,
369 int optname, uint64_t optval);
370CEPH_RBD_API int rbd_image_options_get_string(rbd_image_options_t opts,
371 int optname, char* optval,
372 size_t maxlen);
373CEPH_RBD_API int rbd_image_options_get_uint64(rbd_image_options_t opts,
374 int optname, uint64_t* optval);
375CEPH_RBD_API int rbd_image_options_is_set(rbd_image_options_t opts,
376 int optname, bool* is_set);
377CEPH_RBD_API int rbd_image_options_unset(rbd_image_options_t opts, int optname);
378CEPH_RBD_API void rbd_image_options_clear(rbd_image_options_t opts);
379CEPH_RBD_API int rbd_image_options_is_empty(rbd_image_options_t opts);
380
11fdf7f2
TL
381/* helpers */
382CEPH_RBD_API void rbd_image_spec_cleanup(rbd_image_spec_t *image);
383CEPH_RBD_API void rbd_image_spec_list_cleanup(rbd_image_spec_t *images,
384 size_t num_images);
385CEPH_RBD_API void rbd_linked_image_spec_cleanup(rbd_linked_image_spec_t *image);
386CEPH_RBD_API void rbd_linked_image_spec_list_cleanup(
387 rbd_linked_image_spec_t *images, size_t num_images);
388CEPH_RBD_API void rbd_snap_spec_cleanup(rbd_snap_spec_t *snap);
389
7c673cae 390/* images */
11fdf7f2 391CEPH_RBD_API int rbd_list(rados_ioctx_t io, char *names, size_t *size)
9f95a23c 392 CEPH_RBD_DEPRECATED;
11fdf7f2
TL
393CEPH_RBD_API int rbd_list2(rados_ioctx_t io, rbd_image_spec_t* images,
394 size_t *max_images);
395
7c673cae
FG
396CEPH_RBD_API int rbd_create(rados_ioctx_t io, const char *name, uint64_t size,
397 int *order);
398CEPH_RBD_API int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size,
399 uint64_t features, int *order);
400/**
401 * create new rbd image
402 *
403 * The stripe_unit must be a factor of the object size (1 << order).
404 * The stripe_count can be one (no intra-object striping) or greater
405 * than one. The RBD_FEATURE_STRIPINGV2 must be specified if the
406 * stripe_unit != the object size and the stripe_count is != 1.
407 *
408 * @param io ioctx
409 * @param name image name
410 * @param size image size in bytes
411 * @param features initial feature bits
412 * @param order object/block size, as a power of two (object size == 1 << order)
413 * @param stripe_unit stripe unit size, in bytes.
414 * @param stripe_count number of objects to stripe over before looping
415 * @return 0 on success, or negative error code
416 */
417CEPH_RBD_API int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size,
418 uint64_t features, int *order,
419 uint64_t stripe_unit, uint64_t stripe_count);
420CEPH_RBD_API int rbd_create4(rados_ioctx_t io, const char *name, uint64_t size,
421 rbd_image_options_t opts);
422CEPH_RBD_API int rbd_clone(rados_ioctx_t p_ioctx, const char *p_name,
423 const char *p_snapname, rados_ioctx_t c_ioctx,
424 const char *c_name, uint64_t features, int *c_order);
425CEPH_RBD_API int rbd_clone2(rados_ioctx_t p_ioctx, const char *p_name,
426 const char *p_snapname, rados_ioctx_t c_ioctx,
427 const char *c_name, uint64_t features, int *c_order,
428 uint64_t stripe_unit, int stripe_count);
429CEPH_RBD_API int rbd_clone3(rados_ioctx_t p_ioctx, const char *p_name,
430 const char *p_snapname, rados_ioctx_t c_ioctx,
431 const char *c_name, rbd_image_options_t c_opts);
432CEPH_RBD_API int rbd_remove(rados_ioctx_t io, const char *name);
433CEPH_RBD_API int rbd_remove_with_progress(rados_ioctx_t io, const char *name,
434 librbd_progress_fn_t cb,
435 void *cbdata);
436CEPH_RBD_API int rbd_rename(rados_ioctx_t src_io_ctx, const char *srcname,
437 const char *destname);
438
439CEPH_RBD_API int rbd_trash_move(rados_ioctx_t io, const char *name,
440 uint64_t delay);
441CEPH_RBD_API int rbd_trash_get(rados_ioctx_t io, const char *id,
442 rbd_trash_image_info_t *info);
443CEPH_RBD_API void rbd_trash_get_cleanup(rbd_trash_image_info_t *info);
444CEPH_RBD_API int rbd_trash_list(rados_ioctx_t io,
445 rbd_trash_image_info_t *trash_entries,
446 size_t *num_entries);
447CEPH_RBD_API void rbd_trash_list_cleanup(rbd_trash_image_info_t *trash_entries,
448 size_t num_entries);
11fdf7f2
TL
449CEPH_RBD_API int rbd_trash_purge(rados_ioctx_t io, time_t expire_ts, float threshold);
450CEPH_RBD_API int rbd_trash_purge_with_progress(rados_ioctx_t io, time_t expire_ts,
451 float threshold, librbd_progress_fn_t cb,
452 void* cbdata);
7c673cae 453CEPH_RBD_API int rbd_trash_remove(rados_ioctx_t io, const char *id, bool force);
11fdf7f2
TL
454CEPH_RBD_API int rbd_trash_remove_with_progress(rados_ioctx_t io,
455 const char *id,
456 bool force,
457 librbd_progress_fn_t cb,
7c673cae
FG
458 void *cbdata);
459CEPH_RBD_API int rbd_trash_restore(rados_ioctx_t io, const char *id,
460 const char *name);
461
11fdf7f2
TL
462/* migration */
463CEPH_RBD_API int rbd_migration_prepare(rados_ioctx_t ioctx,
464 const char *image_name,
465 rados_ioctx_t dest_ioctx,
466 const char *dest_image_name,
467 rbd_image_options_t opts);
468CEPH_RBD_API int rbd_migration_execute(rados_ioctx_t ioctx,
469 const char *image_name);
470CEPH_RBD_API int rbd_migration_execute_with_progress(rados_ioctx_t ioctx,
471 const char *image_name,
472 librbd_progress_fn_t cb,
473 void *cbdata);
474CEPH_RBD_API int rbd_migration_abort(rados_ioctx_t ioctx,
475 const char *image_name);
476CEPH_RBD_API int rbd_migration_abort_with_progress(rados_ioctx_t ioctx,
477 const char *image_name,
478 librbd_progress_fn_t cb,
479 void *cbdata);
480CEPH_RBD_API int rbd_migration_commit(rados_ioctx_t ioctx,
481 const char *image_name);
482CEPH_RBD_API int rbd_migration_commit_with_progress(rados_ioctx_t ioctx,
483 const char *image_name,
484 librbd_progress_fn_t cb,
485 void *cbdata);
486CEPH_RBD_API int rbd_migration_status(rados_ioctx_t ioctx,
487 const char *image_name,
488 rbd_image_migration_status_t *status,
489 size_t status_size);
490CEPH_RBD_API void rbd_migration_status_cleanup(
491 rbd_image_migration_status_t *status);
492
7c673cae 493/* pool mirroring */
eafe8130
TL
494CEPH_RBD_API int rbd_mirror_site_name_get(rados_t cluster,
495 char *name, size_t *max_len);
496CEPH_RBD_API int rbd_mirror_site_name_set(rados_t cluster,
497 const char *name);
498
7c673cae
FG
499CEPH_RBD_API int rbd_mirror_mode_get(rados_ioctx_t io_ctx,
500 rbd_mirror_mode_t *mirror_mode);
501CEPH_RBD_API int rbd_mirror_mode_set(rados_ioctx_t io_ctx,
502 rbd_mirror_mode_t mirror_mode);
eafe8130 503
9f95a23c
TL
504CEPH_RBD_API int rbd_mirror_uuid_get(rados_ioctx_t io_ctx,
505 char *uuid, size_t *max_len);
506
507CEPH_RBD_API int rbd_mirror_peer_bootstrap_create(
508 rados_ioctx_t io_ctx, char *token, size_t *max_len);
eafe8130
TL
509CEPH_RBD_API int rbd_mirror_peer_bootstrap_import(
510 rados_ioctx_t io_ctx, rbd_mirror_peer_direction_t direction,
511 const char *token);
512
9f95a23c
TL
513CEPH_RBD_API int rbd_mirror_peer_site_add(
514 rados_ioctx_t io_ctx, char *uuid, size_t uuid_max_length,
515 rbd_mirror_peer_direction_t direction, const char *site_name,
516 const char *client_name);
517CEPH_RBD_API int rbd_mirror_peer_site_set_name(
518 rados_ioctx_t io_ctx, const char *uuid, const char *site_name);
519CEPH_RBD_API int rbd_mirror_peer_site_set_client_name(
520 rados_ioctx_t io_ctx, const char *uuid, const char *client_name);
521CEPH_RBD_API int rbd_mirror_peer_site_set_direction(
522 rados_ioctx_t io_ctx, const char *uuid,
523 rbd_mirror_peer_direction_t direction);
524CEPH_RBD_API int rbd_mirror_peer_site_remove(
525 rados_ioctx_t io_ctx, const char *uuid);
526CEPH_RBD_API int rbd_mirror_peer_site_list(
527 rados_ioctx_t io_ctx, rbd_mirror_peer_site_t *peers, int *max_peers);
528CEPH_RBD_API void rbd_mirror_peer_site_list_cleanup(
529 rbd_mirror_peer_site_t *peers, int max_peers);
530CEPH_RBD_API int rbd_mirror_peer_site_get_attributes(
11fdf7f2
TL
531 rados_ioctx_t p, const char *uuid, char *keys, size_t *max_key_len,
532 char *values, size_t *max_value_len, size_t *key_value_count);
9f95a23c 533CEPH_RBD_API int rbd_mirror_peer_site_set_attributes(
11fdf7f2
TL
534 rados_ioctx_t p, const char *uuid, const char *keys, const char *values,
535 size_t key_value_count);
536
9f95a23c
TL
537CEPH_RBD_API int rbd_mirror_image_global_status_list(
538 rados_ioctx_t io_ctx, const char *start_id, size_t max, char **image_ids,
539 rbd_mirror_image_global_status_t *images, size_t *len);
540CEPH_RBD_API void rbd_mirror_image_global_status_list_cleanup(
541 char **image_ids, rbd_mirror_image_global_status_t *images, size_t len);
542
543/* rbd_mirror_peer_ commands are deprecated to rbd_mirror_peer_site_
544 * equivalents */
545CEPH_RBD_API int rbd_mirror_peer_add(
546 rados_ioctx_t io_ctx, char *uuid, size_t uuid_max_length,
547 const char *cluster_name, const char *client_name)
548 CEPH_RBD_DEPRECATED;
549CEPH_RBD_API int rbd_mirror_peer_remove(
550 rados_ioctx_t io_ctx, const char *uuid)
551 CEPH_RBD_DEPRECATED;
552CEPH_RBD_API int rbd_mirror_peer_list(
553 rados_ioctx_t io_ctx, rbd_mirror_peer_t *peers, int *max_peers)
554 CEPH_RBD_DEPRECATED;
555CEPH_RBD_API void rbd_mirror_peer_list_cleanup(
556 rbd_mirror_peer_t *peers, int max_peers)
557 CEPH_RBD_DEPRECATED;
558CEPH_RBD_API int rbd_mirror_peer_set_client(
559 rados_ioctx_t io_ctx, const char *uuid, const char *client_name)
560 CEPH_RBD_DEPRECATED;
561CEPH_RBD_API int rbd_mirror_peer_set_cluster(
562 rados_ioctx_t io_ctx, const char *uuid, const char *cluster_name)
563 CEPH_RBD_DEPRECATED;
564CEPH_RBD_API int rbd_mirror_peer_get_attributes(
565 rados_ioctx_t p, const char *uuid, char *keys, size_t *max_key_len,
566 char *values, size_t *max_value_len, size_t *key_value_count)
567 CEPH_RBD_DEPRECATED;
568CEPH_RBD_API int rbd_mirror_peer_set_attributes(
569 rados_ioctx_t p, const char *uuid, const char *keys, const char *values,
570 size_t key_value_count)
571 CEPH_RBD_DEPRECATED;
572
573/* rbd_mirror_image_status_list_ commands are deprecard to
574 * rbd_mirror_image_global_status_list_ commands */
575
576CEPH_RBD_API int rbd_mirror_image_status_list(
577 rados_ioctx_t io_ctx, const char *start_id, size_t max, char **image_ids,
578 rbd_mirror_image_status_t *images, size_t *len)
579 CEPH_RBD_DEPRECATED;
580CEPH_RBD_API void rbd_mirror_image_status_list_cleanup(
581 char **image_ids, rbd_mirror_image_status_t *images, size_t len)
582 CEPH_RBD_DEPRECATED;
583
584CEPH_RBD_API int rbd_mirror_image_status_summary(
585 rados_ioctx_t io_ctx, rbd_mirror_image_status_state_t *states, int *counts,
586 size_t *maxlen);
7c673cae 587
11fdf7f2
TL
588CEPH_RBD_API int rbd_mirror_image_instance_id_list(rados_ioctx_t io_ctx,
589 const char *start_id,
590 size_t max, char **image_ids,
591 char **instance_ids,
592 size_t *len);
593CEPH_RBD_API void rbd_mirror_image_instance_id_list_cleanup(char **image_ids,
594 char **instance_ids,
595 size_t len);
9f95a23c
TL
596CEPH_RBD_API int rbd_mirror_image_info_list(
597 rados_ioctx_t io_ctx, rbd_mirror_image_mode_t *mode_filter,
598 const char *start_id, size_t max, char **image_ids,
599 rbd_mirror_image_mode_t *mode_entries,
600 rbd_mirror_image_info_t *info_entries, size_t *num_entries);
601CEPH_RBD_API void rbd_mirror_image_info_list_cleanup(
602 char **image_ids, rbd_mirror_image_info_t *info_entries,
603 size_t num_entries);
11fdf7f2
TL
604
605/* pool metadata */
606CEPH_RBD_API int rbd_pool_metadata_get(rados_ioctx_t io_ctx, const char *key,
607 char *value, size_t *val_len);
608CEPH_RBD_API int rbd_pool_metadata_set(rados_ioctx_t io_ctx, const char *key,
609 const char *value);
610CEPH_RBD_API int rbd_pool_metadata_remove(rados_ioctx_t io_ctx,
611 const char *key);
612CEPH_RBD_API int rbd_pool_metadata_list(rados_ioctx_t io_ctx, const char *start,
613 uint64_t max, char *keys,
614 size_t *key_len, char *values,
615 size_t *vals_len);
616
617CEPH_RBD_API int rbd_config_pool_list(rados_ioctx_t io_ctx,
618 rbd_config_option_t *options,
619 int *max_options);
620CEPH_RBD_API void rbd_config_pool_list_cleanup(rbd_config_option_t *options,
621 int max_options);
622
7c673cae
FG
623CEPH_RBD_API int rbd_open(rados_ioctx_t io, const char *name,
624 rbd_image_t *image, const char *snap_name);
625CEPH_RBD_API int rbd_open_by_id(rados_ioctx_t io, const char *id,
626 rbd_image_t *image, const char *snap_name);
627
628CEPH_RBD_API int rbd_aio_open(rados_ioctx_t io, const char *name,
629 rbd_image_t *image, const char *snap_name,
630 rbd_completion_t c);
631CEPH_RBD_API int rbd_aio_open_by_id(rados_ioctx_t io, const char *id,
632 rbd_image_t *image, const char *snap_name,
633 rbd_completion_t c);
634
635/**
636 * Open an image in read-only mode.
637 *
638 * This is intended for use by clients that cannot write to a block
639 * device due to cephx restrictions. There will be no watch
640 * established on the header object, since a watch is a write. This
641 * means the metadata reported about this image (parents, snapshots,
642 * size, etc.) may become stale. This should not be used for
643 * long-running operations, unless you can be sure that one of these
644 * properties changing is safe.
645 *
646 * Attempting to write to a read-only image will return -EROFS.
647 *
648 * @param io ioctx to determine the pool the image is in
649 * @param name image name
650 * @param image where to store newly opened image handle
651 * @param snap_name name of snapshot to open at, or NULL for no snapshot
652 * @returns 0 on success, negative error code on failure
653 */
654CEPH_RBD_API int rbd_open_read_only(rados_ioctx_t io, const char *name,
655 rbd_image_t *image, const char *snap_name);
656CEPH_RBD_API int rbd_open_by_id_read_only(rados_ioctx_t io, const char *id,
657 rbd_image_t *image, const char *snap_name);
658CEPH_RBD_API int rbd_aio_open_read_only(rados_ioctx_t io, const char *name,
659 rbd_image_t *image, const char *snap_name,
660 rbd_completion_t c);
661CEPH_RBD_API int rbd_aio_open_by_id_read_only(rados_ioctx_t io, const char *id,
662 rbd_image_t *image, const char *snap_name,
663 rbd_completion_t c);
9f95a23c
TL
664CEPH_RBD_API int rbd_features_to_string(uint64_t features, char *str_features,
665 size_t *size);
666CEPH_RBD_API int rbd_features_from_string(const char *str_features, uint64_t *features);
7c673cae
FG
667CEPH_RBD_API int rbd_close(rbd_image_t image);
668CEPH_RBD_API int rbd_aio_close(rbd_image_t image, rbd_completion_t c);
669CEPH_RBD_API int rbd_resize(rbd_image_t image, uint64_t size);
670CEPH_RBD_API int rbd_resize2(rbd_image_t image, uint64_t size, bool allow_shrink,
671 librbd_progress_fn_t cb, void *cbdata);
672CEPH_RBD_API int rbd_resize_with_progress(rbd_image_t image, uint64_t size,
673 librbd_progress_fn_t cb, void *cbdata);
674CEPH_RBD_API int rbd_stat(rbd_image_t image, rbd_image_info_t *info,
675 size_t infosize);
676CEPH_RBD_API int rbd_get_old_format(rbd_image_t image, uint8_t *old);
677CEPH_RBD_API int rbd_get_size(rbd_image_t image, uint64_t *size);
678CEPH_RBD_API int rbd_get_features(rbd_image_t image, uint64_t *features);
679CEPH_RBD_API int rbd_update_features(rbd_image_t image, uint64_t features,
680 uint8_t enabled);
11fdf7f2 681CEPH_RBD_API int rbd_get_op_features(rbd_image_t image, uint64_t *op_features);
7c673cae
FG
682CEPH_RBD_API int rbd_get_stripe_unit(rbd_image_t image, uint64_t *stripe_unit);
683CEPH_RBD_API int rbd_get_stripe_count(rbd_image_t image,
684 uint64_t *stripe_count);
31f18b77
FG
685
686CEPH_RBD_API int rbd_get_create_timestamp(rbd_image_t image,
687 struct timespec *timestamp);
11fdf7f2
TL
688CEPH_RBD_API int rbd_get_access_timestamp(rbd_image_t image,
689 struct timespec *timestamp);
690CEPH_RBD_API int rbd_get_modify_timestamp(rbd_image_t image,
691 struct timespec *timestamp);
31f18b77 692
7c673cae 693CEPH_RBD_API int rbd_get_overlap(rbd_image_t image, uint64_t *overlap);
11fdf7f2 694CEPH_RBD_API int rbd_get_name(rbd_image_t image, char *name, size_t *name_len);
7c673cae
FG
695CEPH_RBD_API int rbd_get_id(rbd_image_t image, char *id, size_t id_len);
696CEPH_RBD_API int rbd_get_block_name_prefix(rbd_image_t image,
697 char *prefix, size_t prefix_len);
698CEPH_RBD_API int64_t rbd_get_data_pool_id(rbd_image_t image);
11fdf7f2 699
7c673cae
FG
700CEPH_RBD_API int rbd_get_parent_info(rbd_image_t image,
701 char *parent_poolname, size_t ppoolnamelen,
702 char *parent_name, size_t pnamelen,
703 char *parent_snapname,
11fdf7f2 704 size_t psnapnamelen)
9f95a23c 705 CEPH_RBD_DEPRECATED;
7c673cae
FG
706CEPH_RBD_API int rbd_get_parent_info2(rbd_image_t image,
707 char *parent_poolname,
708 size_t ppoolnamelen,
709 char *parent_name, size_t pnamelen,
710 char *parent_id, size_t pidlen,
711 char *parent_snapname,
11fdf7f2 712 size_t psnapnamelen)
9f95a23c 713 CEPH_RBD_DEPRECATED;
11fdf7f2
TL
714CEPH_RBD_API int rbd_get_parent(rbd_image_t image,
715 rbd_linked_image_spec_t *parent_image,
716 rbd_snap_spec_t *parent_snap);
717
7c673cae 718CEPH_RBD_API int rbd_get_flags(rbd_image_t image, uint64_t *flags);
11fdf7f2
TL
719CEPH_RBD_API int rbd_get_group(rbd_image_t image, rbd_group_info_t *group_info,
720 size_t group_info_size);
7c673cae
FG
721CEPH_RBD_API int rbd_set_image_notification(rbd_image_t image, int fd, int type);
722
723/* exclusive lock feature */
724CEPH_RBD_API int rbd_is_exclusive_lock_owner(rbd_image_t image, int *is_owner);
725CEPH_RBD_API int rbd_lock_acquire(rbd_image_t image, rbd_lock_mode_t lock_mode);
726CEPH_RBD_API int rbd_lock_release(rbd_image_t image);
727CEPH_RBD_API int rbd_lock_get_owners(rbd_image_t image,
728 rbd_lock_mode_t *lock_mode,
729 char **lock_owners,
730 size_t *max_lock_owners);
731CEPH_RBD_API void rbd_lock_get_owners_cleanup(char **lock_owners,
732 size_t lock_owner_count);
733CEPH_RBD_API int rbd_lock_break(rbd_image_t image, rbd_lock_mode_t lock_mode,
734 const char *lock_owner);
735
736/* object map feature */
737CEPH_RBD_API int rbd_rebuild_object_map(rbd_image_t image,
738 librbd_progress_fn_t cb, void *cbdata);
739
740CEPH_RBD_API int rbd_copy(rbd_image_t image, rados_ioctx_t dest_io_ctx,
741 const char *destname);
742CEPH_RBD_API int rbd_copy2(rbd_image_t src, rbd_image_t dest);
743CEPH_RBD_API int rbd_copy3(rbd_image_t src, rados_ioctx_t dest_io_ctx,
744 const char *destname, rbd_image_options_t dest_opts);
745CEPH_RBD_API int rbd_copy4(rbd_image_t src, rados_ioctx_t dest_io_ctx,
746 const char *destname, rbd_image_options_t dest_opts,
747 size_t sparse_size);
748CEPH_RBD_API int rbd_copy_with_progress(rbd_image_t image, rados_ioctx_t dest_p,
749 const char *destname,
750 librbd_progress_fn_t cb, void *cbdata);
751CEPH_RBD_API int rbd_copy_with_progress2(rbd_image_t src, rbd_image_t dest,
752 librbd_progress_fn_t cb, void *cbdata);
753CEPH_RBD_API int rbd_copy_with_progress3(rbd_image_t image,
754 rados_ioctx_t dest_p,
755 const char *destname,
756 rbd_image_options_t dest_opts,
757 librbd_progress_fn_t cb, void *cbdata);
758CEPH_RBD_API int rbd_copy_with_progress4(rbd_image_t image,
759 rados_ioctx_t dest_p,
760 const char *destname,
761 rbd_image_options_t dest_opts,
762 librbd_progress_fn_t cb, void *cbdata,
763 size_t sparse_size);
764
11fdf7f2
TL
765/* deep copy */
766CEPH_RBD_API int rbd_deep_copy(rbd_image_t src, rados_ioctx_t dest_io_ctx,
767 const char *destname,
768 rbd_image_options_t dest_opts);
769CEPH_RBD_API int rbd_deep_copy_with_progress(rbd_image_t image,
770 rados_ioctx_t dest_io_ctx,
771 const char *destname,
772 rbd_image_options_t dest_opts,
773 librbd_progress_fn_t cb,
774 void *cbdata);
775
7c673cae
FG
776/* snapshots */
777CEPH_RBD_API int rbd_snap_list(rbd_image_t image, rbd_snap_info_t *snaps,
778 int *max_snaps);
779CEPH_RBD_API void rbd_snap_list_end(rbd_snap_info_t *snaps);
9f95a23c 780CEPH_RBD_API int rbd_snap_exists(rbd_image_t image, const char *snapname, bool *exists);
7c673cae
FG
781CEPH_RBD_API int rbd_snap_create(rbd_image_t image, const char *snapname);
782CEPH_RBD_API int rbd_snap_remove(rbd_image_t image, const char *snapname);
11fdf7f2
TL
783CEPH_RBD_API int rbd_snap_remove2(rbd_image_t image, const char *snap_name,
784 uint32_t flags, librbd_progress_fn_t cb,
785 void *cbdata);
786CEPH_RBD_API int rbd_snap_remove_by_id(rbd_image_t image, uint64_t snap_id);
7c673cae
FG
787CEPH_RBD_API int rbd_snap_rollback(rbd_image_t image, const char *snapname);
788CEPH_RBD_API int rbd_snap_rollback_with_progress(rbd_image_t image,
789 const char *snapname,
790 librbd_progress_fn_t cb,
791 void *cbdata);
792CEPH_RBD_API int rbd_snap_rename(rbd_image_t image, const char *snapname,
793 const char* dstsnapsname);
794/**
795 * Prevent a snapshot from being deleted until it is unprotected.
796 *
797 * @param snap_name which snapshot to protect
798 * @returns 0 on success, negative error code on failure
799 * @returns -EBUSY if snap is already protected
800 */
801CEPH_RBD_API int rbd_snap_protect(rbd_image_t image, const char *snap_name);
802/**
803 * Allow a snaphshot to be deleted.
804 *
805 * @param snap_name which snapshot to unprotect
806 * @returns 0 on success, negative error code on failure
807 * @returns -EINVAL if snap is not protected
808 */
809CEPH_RBD_API int rbd_snap_unprotect(rbd_image_t image, const char *snap_name);
810/**
811 * Determine whether a snapshot is protected.
812 *
813 * @param snap_name which snapshot query
814 * @param is_protected where to store the result (0 or 1)
815 * @returns 0 on success, negative error code on failure
816 */
817CEPH_RBD_API int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,
818 int *is_protected);
819/**
820 * Get the current snapshot limit for an image. If no limit is set,
821 * UINT64_MAX is returned.
822 *
823 * @param limit pointer where the limit will be stored on success
824 * @returns 0 on success, negative error code on failure
825 */
826CEPH_RBD_API int rbd_snap_get_limit(rbd_image_t image, uint64_t *limit);
827
828/**
829 * Set a limit for the number of snapshots that may be taken of an image.
830 *
831 * @param limit the maximum number of snapshots allowed in the future.
832 * @returns 0 on success, negative error code on failure
833 */
834CEPH_RBD_API int rbd_snap_set_limit(rbd_image_t image, uint64_t limit);
835
836/**
837 * Get the timestamp of a snapshot for an image.
838 *
839 * @param snap_id the snap id of a snapshot of input image.
840 * @param timestamp the timestamp of input snapshot.
841 * @returns 0 on success, negative error code on failure
842 */
843CEPH_RBD_API int rbd_snap_get_timestamp(rbd_image_t image, uint64_t snap_id, struct timespec *timestamp);
844
845CEPH_RBD_API int rbd_snap_set(rbd_image_t image, const char *snapname);
11fdf7f2 846CEPH_RBD_API int rbd_snap_set_by_id(rbd_image_t image, uint64_t snap_id);
9f95a23c
TL
847CEPH_RBD_API int rbd_snap_get_name(rbd_image_t image, uint64_t snap_id, char *snapname, size_t *name_len);
848CEPH_RBD_API int rbd_snap_get_id(rbd_image_t image, const char *snapname, uint64_t *snap_id);
11fdf7f2
TL
849
850CEPH_RBD_API int rbd_snap_get_namespace_type(rbd_image_t image,
851 uint64_t snap_id,
852 rbd_snap_namespace_type_t *namespace_type);
853CEPH_RBD_API int rbd_snap_get_group_namespace(rbd_image_t image,
854 uint64_t snap_id,
855 rbd_snap_group_namespace_t *group_snap,
856 size_t group_snap_size);
857CEPH_RBD_API int rbd_snap_group_namespace_cleanup(rbd_snap_group_namespace_t *group_snap,
858 size_t group_snap_size);
859CEPH_RBD_API int rbd_snap_get_trash_namespace(rbd_image_t image,
860 uint64_t snap_id,
861 char* original_name,
862 size_t max_length);
9f95a23c
TL
863CEPH_RBD_API int rbd_snap_get_mirror_namespace(
864 rbd_image_t image, uint64_t snap_id,
865 rbd_snap_mirror_namespace_t *mirror_snap, size_t mirror_snap_size);
866CEPH_RBD_API int rbd_snap_mirror_namespace_cleanup(
867 rbd_snap_mirror_namespace_t *mirror_snap, size_t mirror_snap_size);
7c673cae
FG
868
869CEPH_RBD_API int rbd_flatten(rbd_image_t image);
870
871CEPH_RBD_API int rbd_flatten_with_progress(rbd_image_t image,
872 librbd_progress_fn_t cb,
873 void *cbdata);
874
11fdf7f2
TL
875CEPH_RBD_API int rbd_sparsify(rbd_image_t image, size_t sparse_size);
876
877CEPH_RBD_API int rbd_sparsify_with_progress(rbd_image_t image,
878 size_t sparse_size,
879 librbd_progress_fn_t cb,
880 void *cbdata);
881
7c673cae
FG
882/**
883 * List all images that are cloned from the image at the
884 * snapshot that is set via rbd_snap_set().
885 *
886 * This iterates over all pools, so it should be run by a user with
887 * read access to all of them. pools_len and images_len are filled in
888 * with the number of bytes put into the pools and images buffers.
889 *
890 * If the provided buffers are too short, the required lengths are
891 * still filled in, but the data is not and -ERANGE is returned.
892 * Otherwise, the buffers are filled with the pool and image names
893 * of the children, with a '\0' after each.
894 *
895 * @param image which image (and implicitly snapshot) to list clones of
896 * @param pools buffer in which to store pool names
897 * @param pools_len number of bytes in pools buffer
898 * @param images buffer in which to store image names
899 * @param images_len number of bytes in images buffer
900 * @returns number of children on success, negative error code on failure
901 * @returns -ERANGE if either buffer is too short
902 */
903CEPH_RBD_API ssize_t rbd_list_children(rbd_image_t image, char *pools,
904 size_t *pools_len, char *images,
11fdf7f2 905 size_t *images_len)
9f95a23c 906 CEPH_RBD_DEPRECATED;
11fdf7f2
TL
907CEPH_RBD_API int rbd_list_children2(rbd_image_t image,
908 rbd_child_info_t *children,
909 int *max_children)
9f95a23c 910 CEPH_RBD_DEPRECATED;
11fdf7f2 911CEPH_RBD_API void rbd_list_child_cleanup(rbd_child_info_t *child)
9f95a23c 912 CEPH_RBD_DEPRECATED;
11fdf7f2
TL
913CEPH_RBD_API void rbd_list_children_cleanup(rbd_child_info_t *children,
914 size_t num_children)
9f95a23c 915 CEPH_RBD_DEPRECATED;
11fdf7f2
TL
916
917CEPH_RBD_API int rbd_list_children3(rbd_image_t image,
918 rbd_linked_image_spec_t *images,
919 size_t *max_images);
920
921CEPH_RBD_API int rbd_list_descendants(rbd_image_t image,
922 rbd_linked_image_spec_t *images,
923 size_t *max_images);
7c673cae
FG
924
925/**
926 * @defgroup librbd_h_locking Advisory Locking
927 *
928 * An rbd image may be locking exclusively, or shared, to facilitate
929 * e.g. live migration where the image may be open in two places at once.
930 * These locks are intended to guard against more than one client
931 * writing to an image without coordination. They don't need to
932 * be used for snapshots, since snapshots are read-only.
933 *
934 * Currently locks only guard against locks being acquired.
935 * They do not prevent anything else.
936 *
937 * A locker is identified by the internal rados client id of the
938 * holder and a user-defined cookie. This (client id, cookie) pair
939 * must be unique for each locker.
940 *
941 * A shared lock also has a user-defined tag associated with it. Each
942 * additional shared lock must specify the same tag or lock
943 * acquisition will fail. This can be used by e.g. groups of hosts
944 * using a clustered filesystem on top of an rbd image to make sure
945 * they're accessing the correct image.
946 *
947 * @{
948 */
949/**
950 * List clients that have locked the image and information about the lock.
951 *
952 * The number of bytes required in each buffer is put in the
953 * corresponding size out parameter. If any of the provided buffers
954 * are too short, -ERANGE is returned after these sizes are filled in.
955 *
956 * @param exclusive where to store whether the lock is exclusive (1) or shared (0)
957 * @param tag where to store the tag associated with the image
958 * @param tag_len number of bytes in tag buffer
959 * @param clients buffer in which locker clients are stored, separated by '\0'
960 * @param clients_len number of bytes in the clients buffer
961 * @param cookies buffer in which locker cookies are stored, separated by '\0'
962 * @param cookies_len number of bytes in the cookies buffer
963 * @param addrs buffer in which locker addresses are stored, separated by '\0'
964 * @param addrs_len number of bytes in the clients buffer
965 * @returns number of lockers on success, negative error code on failure
966 * @returns -ERANGE if any of the buffers are too short
967 */
968CEPH_RBD_API ssize_t rbd_list_lockers(rbd_image_t image, int *exclusive,
969 char *tag, size_t *tag_len,
970 char *clients, size_t *clients_len,
971 char *cookies, size_t *cookies_len,
972 char *addrs, size_t *addrs_len);
973
974/**
975 * Take an exclusive lock on the image.
976 *
977 * @param image the image to lock
978 * @param cookie user-defined identifier for this instance of the lock
979 * @returns 0 on success, negative error code on failure
980 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
981 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
982 */
983CEPH_RBD_API int rbd_lock_exclusive(rbd_image_t image, const char *cookie);
984
985/**
986 * Take a shared lock on the image.
987 *
988 * Other clients may also take a shared lock, as lock as they use the
989 * same tag.
990 *
991 * @param image the image to lock
992 * @param cookie user-defined identifier for this instance of the lock
993 * @param tag user-defined identifier for this shared use of the lock
994 * @returns 0 on success, negative error code on failure
995 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
996 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
997 */
998CEPH_RBD_API int rbd_lock_shared(rbd_image_t image, const char *cookie,
999 const char *tag);
1000
1001/**
1002 * Release a shared or exclusive lock on the image.
1003 *
1004 * @param image the image to unlock
1005 * @param cookie user-defined identifier for the instance of the lock
1006 * @returns 0 on success, negative error code on failure
1007 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
1008 */
1009CEPH_RBD_API int rbd_unlock(rbd_image_t image, const char *cookie);
1010
1011/**
1012 * Release a shared or exclusive lock that was taken by the specified client.
1013 *
1014 * @param image the image to unlock
1015 * @param client the entity holding the lock (as given by rbd_list_lockers())
1016 * @param cookie user-defined identifier for the instance of the lock to break
1017 * @returns 0 on success, negative error code on failure
1018 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
1019 */
1020CEPH_RBD_API int rbd_break_lock(rbd_image_t image, const char *client,
1021 const char *cookie);
1022
1023/** @} locking */
1024
1025/* I/O */
1026CEPH_RBD_API ssize_t rbd_read(rbd_image_t image, uint64_t ofs, size_t len,
1027 char *buf);
1028/*
1029 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
1030 */
1031CEPH_RBD_API ssize_t rbd_read2(rbd_image_t image, uint64_t ofs, size_t len,
1032 char *buf, int op_flags);
1033/* DEPRECATED; use rbd_read_iterate2 */
1034CEPH_RBD_API int64_t rbd_read_iterate(rbd_image_t image, uint64_t ofs, size_t len,
1035 int (*cb)(uint64_t, size_t, const char *, void *),
1036 void *arg);
1037
1038/**
1039 * iterate read over an image
1040 *
1041 * Reads each region of the image and calls the callback. If the
1042 * buffer pointer passed to the callback is NULL, the given extent is
1043 * defined to be zeros (a hole). Normally the granularity for the
1044 * callback is the image stripe size.
1045 *
1046 * @param image image to read
1047 * @param ofs offset to start from
1048 * @param len bytes of source image to cover
1049 * @param cb callback for each region
1050 * @returns 0 success, error otherwise
1051 */
1052CEPH_RBD_API int rbd_read_iterate2(rbd_image_t image, uint64_t ofs, uint64_t len,
1053 int (*cb)(uint64_t, size_t, const char *, void *),
1054 void *arg);
1055/**
1056 * get difference between two versions of an image
1057 *
1058 * This will return the differences between two versions of an image
1059 * via a callback, which gets the offset and length and a flag
1060 * indicating whether the extent exists (1), or is known/defined to
1061 * be zeros (a hole, 0). If the source snapshot name is NULL, we
1062 * interpret that as the beginning of time and return all allocated
1063 * regions of the image. The end version is whatever is currently
1064 * selected for the image handle (either a snapshot or the writeable
1065 * head).
1066 *
1067 * @param fromsnapname start snapshot name, or NULL
1068 * @param ofs start offset
1069 * @param len len in bytes of region to report on
1070 * @param include_parent 1 if full history diff should include parent
1071 * @param whole_object 1 if diff extents should cover whole object
1072 * @param cb callback to call for each allocated region
1073 * @param arg argument to pass to the callback
1074 * @returns 0 on success, or negative error code on error
1075 */
1076CEPH_RBD_API int rbd_diff_iterate(rbd_image_t image,
1077 const char *fromsnapname,
1078 uint64_t ofs, uint64_t len,
1079 int (*cb)(uint64_t, size_t, int, void *),
1080 void *arg);
1081CEPH_RBD_API int rbd_diff_iterate2(rbd_image_t image,
1082 const char *fromsnapname,
1083 uint64_t ofs, uint64_t len,
1084 uint8_t include_parent, uint8_t whole_object,
1085 int (*cb)(uint64_t, size_t, int, void *),
1086 void *arg);
1087CEPH_RBD_API ssize_t rbd_write(rbd_image_t image, uint64_t ofs, size_t len,
1088 const char *buf);
1089/*
1090 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
1091 */
1092CEPH_RBD_API ssize_t rbd_write2(rbd_image_t image, uint64_t ofs, size_t len,
1093 const char *buf, int op_flags);
1094CEPH_RBD_API int rbd_discard(rbd_image_t image, uint64_t ofs, uint64_t len);
1095CEPH_RBD_API ssize_t rbd_writesame(rbd_image_t image, uint64_t ofs, size_t len,
1096 const char *buf, size_t data_len, int op_flags);
c07f9fc5
FG
1097CEPH_RBD_API ssize_t rbd_compare_and_write(rbd_image_t image, uint64_t ofs,
1098 size_t len, const char *cmp_buf,
1099 const char *buf, uint64_t *mismatch_off,
1100 int op_flags);
1101
7c673cae
FG
1102CEPH_RBD_API int rbd_aio_write(rbd_image_t image, uint64_t off, size_t len,
1103 const char *buf, rbd_completion_t c);
1104
1105/*
1106 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
1107 */
1108CEPH_RBD_API int rbd_aio_write2(rbd_image_t image, uint64_t off, size_t len,
1109 const char *buf, rbd_completion_t c,
1110 int op_flags);
1111CEPH_RBD_API int rbd_aio_writev(rbd_image_t image, const struct iovec *iov,
1112 int iovcnt, uint64_t off, rbd_completion_t c);
1113CEPH_RBD_API int rbd_aio_read(rbd_image_t image, uint64_t off, size_t len,
1114 char *buf, rbd_completion_t c);
1115/*
1116 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
1117 */
1118CEPH_RBD_API int rbd_aio_read2(rbd_image_t image, uint64_t off, size_t len,
1119 char *buf, rbd_completion_t c, int op_flags);
1120CEPH_RBD_API int rbd_aio_readv(rbd_image_t image, const struct iovec *iov,
1121 int iovcnt, uint64_t off, rbd_completion_t c);
1122CEPH_RBD_API int rbd_aio_discard(rbd_image_t image, uint64_t off, uint64_t len,
1123 rbd_completion_t c);
1124CEPH_RBD_API int rbd_aio_writesame(rbd_image_t image, uint64_t off, size_t len,
1125 const char *buf, size_t data_len,
1126 rbd_completion_t c, int op_flags);
c07f9fc5
FG
1127CEPH_RBD_API ssize_t rbd_aio_compare_and_write(rbd_image_t image,
1128 uint64_t off, size_t len,
1129 const char *cmp_buf, const char *buf,
1130 rbd_completion_t c, uint64_t *mismatch_off,
1131 int op_flags);
7c673cae
FG
1132
1133CEPH_RBD_API int rbd_aio_create_completion(void *cb_arg,
1134 rbd_callback_t complete_cb,
1135 rbd_completion_t *c);
1136CEPH_RBD_API int rbd_aio_is_complete(rbd_completion_t c);
1137CEPH_RBD_API int rbd_aio_wait_for_complete(rbd_completion_t c);
1138CEPH_RBD_API ssize_t rbd_aio_get_return_value(rbd_completion_t c);
1139CEPH_RBD_API void *rbd_aio_get_arg(rbd_completion_t c);
1140CEPH_RBD_API void rbd_aio_release(rbd_completion_t c);
1141CEPH_RBD_API int rbd_flush(rbd_image_t image);
1142/**
1143 * Start a flush if caching is enabled. Get a callback when
1144 * the currently pending writes are on disk.
1145 *
1146 * @param image the image to flush writes to
1147 * @param c what to call when flushing is complete
1148 * @returns 0 on success, negative error code on failure
1149 */
1150CEPH_RBD_API int rbd_aio_flush(rbd_image_t image, rbd_completion_t c);
1151
1152/**
1153 * Drop any cached data for an image
1154 *
1155 * @param image the image to invalidate cached data for
1156 * @returns 0 on success, negative error code on failure
1157 */
1158CEPH_RBD_API int rbd_invalidate_cache(rbd_image_t image);
1159
1160CEPH_RBD_API int rbd_poll_io_events(rbd_image_t image, rbd_completion_t *comps, int numcomp);
1161
1162CEPH_RBD_API int rbd_metadata_get(rbd_image_t image, const char *key, char *value, size_t *val_len);
1163CEPH_RBD_API int rbd_metadata_set(rbd_image_t image, const char *key, const char *value);
1164CEPH_RBD_API int rbd_metadata_remove(rbd_image_t image, const char *key);
1165/**
1166 * List all metadatas associated with this image.
1167 *
1168 * This iterates over all metadatas, key_len and val_len are filled in
1169 * with the number of bytes put into the keys and values buffers.
1170 *
1171 * If the provided buffers are too short, the required lengths are
1172 * still filled in, but the data is not and -ERANGE is returned.
1173 * Otherwise, the buffers are filled with the keys and values
1174 * of the image, with a '\0' after each.
1175 *
1176 * @param image which image (and implicitly snapshot) to list clones of
1177 * @param start_after which name to begin listing after
1178 * (use the empty string to start at the beginning)
1179 * @param max the maximum number of names to lis(if 0 means no limit)
1180 * @param keys buffer in which to store pool names
1181 * @param keys_len number of bytes in pools buffer
1182 * @param values buffer in which to store image names
1183 * @param vals_len number of bytes in images buffer
1184 * @returns number of children on success, negative error code on failure
1185 * @returns -ERANGE if either buffer is too short
1186 */
1187CEPH_RBD_API int rbd_metadata_list(rbd_image_t image, const char *start, uint64_t max,
1188 char *keys, size_t *key_len, char *values, size_t *vals_len);
1189
1190// RBD image mirroring support functions
9f95a23c
TL
1191CEPH_RBD_API int rbd_mirror_image_enable(rbd_image_t image) CEPH_RBD_DEPRECATED;
1192CEPH_RBD_API int rbd_mirror_image_enable2(rbd_image_t image,
1193 rbd_mirror_image_mode_t mode);
7c673cae
FG
1194CEPH_RBD_API int rbd_mirror_image_disable(rbd_image_t image, bool force);
1195CEPH_RBD_API int rbd_mirror_image_promote(rbd_image_t image, bool force);
1196CEPH_RBD_API int rbd_mirror_image_demote(rbd_image_t image);
1197CEPH_RBD_API int rbd_mirror_image_resync(rbd_image_t image);
9f95a23c
TL
1198CEPH_RBD_API int rbd_mirror_image_create_snapshot(rbd_image_t image,
1199 uint64_t *snap_id);
7c673cae
FG
1200CEPH_RBD_API int rbd_mirror_image_get_info(rbd_image_t image,
1201 rbd_mirror_image_info_t *mirror_image_info,
1202 size_t info_size);
9f95a23c
TL
1203CEPH_RBD_API void rbd_mirror_image_get_info_cleanup(
1204 rbd_mirror_image_info_t *mirror_image_info);
1205CEPH_RBD_API int rbd_mirror_image_get_mode(rbd_image_t image,
1206 rbd_mirror_image_mode_t *mode);
1207
1208CEPH_RBD_API int rbd_mirror_image_get_global_status(
1209 rbd_image_t image,
1210 rbd_mirror_image_global_status_t *mirror_image_global_status,
1211 size_t status_size);
1212CEPH_RBD_API void rbd_mirror_image_global_status_cleanup(
1213 rbd_mirror_image_global_status_t *mirror_image_global_status);
1214
1215CEPH_RBD_API int rbd_mirror_image_get_status(
1216 rbd_image_t image, rbd_mirror_image_status_t *mirror_image_status,
1217 size_t status_size)
1218 CEPH_RBD_DEPRECATED;
1219
11fdf7f2
TL
1220CEPH_RBD_API int rbd_mirror_image_get_instance_id(rbd_image_t image,
1221 char *instance_id,
1222 size_t *id_max_length);
7c673cae
FG
1223CEPH_RBD_API int rbd_aio_mirror_image_promote(rbd_image_t image, bool force,
1224 rbd_completion_t c);
1225CEPH_RBD_API int rbd_aio_mirror_image_demote(rbd_image_t image,
1226 rbd_completion_t c);
1227CEPH_RBD_API int rbd_aio_mirror_image_get_info(rbd_image_t image,
1228 rbd_mirror_image_info_t *mirror_image_info,
1229 size_t info_size,
1230 rbd_completion_t c);
9f95a23c
TL
1231
1232CEPH_RBD_API int rbd_aio_mirror_image_get_global_status(
1233 rbd_image_t image,
1234 rbd_mirror_image_global_status_t *mirror_global_image_status,
1235 size_t status_size, rbd_completion_t c);
1236CEPH_RBD_API int rbd_aio_mirror_image_get_status(
1237 rbd_image_t image, rbd_mirror_image_status_t *mirror_image_status,
1238 size_t status_size, rbd_completion_t c)
1239 CEPH_RBD_DEPRECATED;
7c673cae 1240
11fdf7f2
TL
1241// RBD groups support functions
1242CEPH_RBD_API int rbd_group_create(rados_ioctx_t p, const char *name);
1243CEPH_RBD_API int rbd_group_remove(rados_ioctx_t p, const char *name);
1244CEPH_RBD_API int rbd_group_list(rados_ioctx_t p, char *names, size_t *size);
1245CEPH_RBD_API int rbd_group_rename(rados_ioctx_t p, const char *src_name,
1246 const char *dest_name);
1247CEPH_RBD_API int rbd_group_info_cleanup(rbd_group_info_t *group_info,
1248 size_t group_info_size);
1249
7c673cae
FG
1250/**
1251 * Register an image metadata change watcher.
1252 *
1253 * @param image the image to watch
1254 * @param handle where to store the internal id assigned to this watch
1255 * @param watch_cb what to do when a notify is received on this image
1256 * @param arg opaque value to pass to the callback
1257 * @returns 0 on success, negative error code on failure
1258 */
1259CEPH_RBD_API int rbd_update_watch(rbd_image_t image, uint64_t *handle,
1260 rbd_update_callback_t watch_cb, void *arg);
1261
1262/**
1263 * Unregister an image watcher.
1264 *
1265 * @param image the image to unwatch
1266 * @param handle which watch to unregister
1267 * @returns 0 on success, negative error code on failure
1268 */
1269CEPH_RBD_API int rbd_update_unwatch(rbd_image_t image, uint64_t handle);
1270
11fdf7f2
TL
1271/**
1272 * List any watchers of an image.
1273 *
1274 * Watchers will be allocated and stored in the passed watchers array. If there
1275 * are more watchers than max_watchers, -ERANGE will be returned and the number
1276 * of watchers will be stored in max_watchers.
1277 *
1278 * The caller should call rbd_watchers_list_cleanup when finished with the list
1279 * of watchers.
1280 *
1281 * @param image the image to list watchers for.
1282 * @param watchers an array to store watchers in.
1283 * @param max_watchers capacity of the watchers array.
1284 * @returns 0 on success, negative error code on failure.
1285 * @returns -ERANGE if there are too many watchers for the passed array.
1286 * @returns the number of watchers in max_watchers.
1287 */
1288CEPH_RBD_API int rbd_watchers_list(rbd_image_t image,
1289 rbd_image_watcher_t *watchers,
1290 size_t *max_watchers);
1291
1292CEPH_RBD_API void rbd_watchers_list_cleanup(rbd_image_watcher_t *watchers,
1293 size_t num_watchers);
1294
1295CEPH_RBD_API int rbd_config_image_list(rbd_image_t image,
1296 rbd_config_option_t *options,
1297 int *max_options);
1298CEPH_RBD_API void rbd_config_image_list_cleanup(rbd_config_option_t *options,
1299 int max_options);
1300
1301CEPH_RBD_API int rbd_group_image_add(rados_ioctx_t group_p,
1302 const char *group_name,
1303 rados_ioctx_t image_p,
1304 const char *image_name);
1305CEPH_RBD_API int rbd_group_image_remove(rados_ioctx_t group_p,
1306 const char *group_name,
1307 rados_ioctx_t image_p,
1308 const char *image_name);
1309CEPH_RBD_API int rbd_group_image_remove_by_id(rados_ioctx_t group_p,
1310 const char *group_name,
1311 rados_ioctx_t image_p,
1312 const char *image_id);
1313CEPH_RBD_API int rbd_group_image_list(rados_ioctx_t group_p,
1314 const char *group_name,
1315 rbd_group_image_info_t *images,
1316 size_t group_image_info_size,
1317 size_t *num_entries);
1318CEPH_RBD_API int rbd_group_image_list_cleanup(rbd_group_image_info_t *images,
1319 size_t group_image_info_size,
1320 size_t num_entries);
1321
1322CEPH_RBD_API int rbd_group_snap_create(rados_ioctx_t group_p,
1323 const char *group_name,
1324 const char *snap_name);
1325CEPH_RBD_API int rbd_group_snap_remove(rados_ioctx_t group_p,
1326 const char *group_name,
1327 const char *snap_name);
1328CEPH_RBD_API int rbd_group_snap_rename(rados_ioctx_t group_p,
1329 const char *group_name,
1330 const char *old_snap_name,
1331 const char *new_snap_name);
1332CEPH_RBD_API int rbd_group_snap_list(rados_ioctx_t group_p,
1333 const char *group_name,
1334 rbd_group_snap_info_t *snaps,
1335 size_t group_snap_info_size,
1336 size_t *num_entries);
1337CEPH_RBD_API int rbd_group_snap_list_cleanup(rbd_group_snap_info_t *snaps,
1338 size_t group_snap_info_size,
1339 size_t num_entries);
1340CEPH_RBD_API int rbd_group_snap_rollback(rados_ioctx_t group_p,
1341 const char *group_name,
1342 const char *snap_name);
1343CEPH_RBD_API int rbd_group_snap_rollback_with_progress(rados_ioctx_t group_p,
1344 const char *group_name,
1345 const char *snap_name,
1346 librbd_progress_fn_t cb,
1347 void *cbdata);
1348
1349CEPH_RBD_API int rbd_namespace_create(rados_ioctx_t io,
1350 const char *namespace_name);
1351CEPH_RBD_API int rbd_namespace_remove(rados_ioctx_t io,
1352 const char *namespace_name);
1353CEPH_RBD_API int rbd_namespace_list(rados_ioctx_t io, char *namespace_names,
1354 size_t *size);
1355CEPH_RBD_API int rbd_namespace_exists(rados_ioctx_t io,
1356 const char *namespace_name,
1357 bool *exists);
1358
1359CEPH_RBD_API int rbd_pool_init(rados_ioctx_t io, bool force);
1360
1361CEPH_RBD_API void rbd_pool_stats_create(rbd_pool_stats_t *stats);
1362CEPH_RBD_API void rbd_pool_stats_destroy(rbd_pool_stats_t stats);
1363CEPH_RBD_API int rbd_pool_stats_option_add_uint64(rbd_pool_stats_t stats,
1364 int stat_option,
1365 uint64_t* stat_val);
1366CEPH_RBD_API int rbd_pool_stats_get(rados_ioctx_t io, rbd_pool_stats_t stats);
1367
9f95a23c
TL
1368#if __GNUC__ >= 4
1369 #pragma GCC diagnostic pop
1370#endif
1371
7c673cae
FG
1372#ifdef __cplusplus
1373}
1374#endif
1375
9f95a23c 1376#endif /* CEPH_LIBRBD_H */