1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
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.
22 #include <netinet/in.h>
23 #if defined(__linux__)
24 #include <linux/types.h>
25 #elif defined(__FreeBSD__)
26 #include <sys/types.h>
31 #include "../rados/librados.h"
34 #define LIBRBD_VER_MAJOR 1
35 #define LIBRBD_VER_MINOR 12
36 #define LIBRBD_VER_EXTRA 0
38 #define LIBRBD_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
40 #define LIBRBD_VERSION_CODE LIBRBD_VERSION(LIBRBD_VER_MAJOR, LIBRBD_VER_MINOR, LIBRBD_VER_EXTRA)
42 #define LIBRBD_SUPPORTS_AIO_FLUSH 1
43 #define LIBRBD_SUPPORTS_AIO_OPEN 1
44 #define LIBRBD_SUPPORTS_LOCKING 1
45 #define LIBRBD_SUPPORTS_INVALIDATE 1
46 #define LIBRBD_SUPPORTS_IOVEC 1
47 #define LIBRBD_SUPPORTS_WATCH 0
50 #define CEPH_RBD_API __attribute__ ((visibility ("default")))
55 #define RBD_FLAG_OBJECT_MAP_INVALID (1<<0)
56 #define RBD_FLAG_FAST_DIFF_INVALID (1<<1)
58 typedef void *rbd_snap_t
;
59 typedef void *rbd_image_t
;
60 typedef void *rbd_image_options_t
;
62 typedef void *rbd_completion_t
;
63 typedef void (*rbd_callback_t
)(rbd_completion_t cb
, void *arg
);
65 typedef int (*librbd_progress_fn_t
)(uint64_t offset
, uint64_t total
, void *ptr
);
67 typedef void (*rbd_update_callback_t
)(void *arg
);
75 #define RBD_MAX_IMAGE_NAME_SIZE 96
76 #define RBD_MAX_BLOCK_NAME_SIZE 24
78 #define RBD_SNAP_REMOVE_UNPROTECT 1 << 0
79 #define RBD_SNAP_REMOVE_FLATTEN 1 << 1
80 #define RBD_SNAP_REMOVE_FORCE (RBD_SNAP_REMOVE_UNPROTECT | RBD_SNAP_REMOVE_FLATTEN)
83 * These types used to in set_image_notification to indicate the type of event
88 EVENT_TYPE_EVENTFD
= 2
96 char block_name_prefix
[RBD_MAX_BLOCK_NAME_SIZE
]; /* deprecated */
97 int64_t parent_pool
; /* deprecated */
98 char parent_name
[RBD_MAX_IMAGE_NAME_SIZE
]; /* deprecated */
102 RBD_MIRROR_MODE_DISABLED
, /* mirroring is disabled */
103 RBD_MIRROR_MODE_IMAGE
, /* mirroring enabled on a per-image basis */
104 RBD_MIRROR_MODE_POOL
/* mirroring enabled on all journaled images */
114 RBD_MIRROR_IMAGE_DISABLING
= 0,
115 RBD_MIRROR_IMAGE_ENABLED
= 1,
116 RBD_MIRROR_IMAGE_DISABLED
= 2
117 } rbd_mirror_image_state_t
;
121 rbd_mirror_image_state_t state
;
123 } rbd_mirror_image_info_t
;
126 MIRROR_IMAGE_STATUS_STATE_UNKNOWN
= 0,
127 MIRROR_IMAGE_STATUS_STATE_ERROR
= 1,
128 MIRROR_IMAGE_STATUS_STATE_SYNCING
= 2,
129 MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY
= 3,
130 MIRROR_IMAGE_STATUS_STATE_REPLAYING
= 4,
131 MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY
= 5,
132 MIRROR_IMAGE_STATUS_STATE_STOPPED
= 6,
133 } rbd_mirror_image_status_state_t
;
137 rbd_mirror_image_info_t info
;
138 rbd_mirror_image_status_state_t state
;
142 } rbd_mirror_image_status_t
;
145 GROUP_IMAGE_STATE_ATTACHED
,
146 GROUP_IMAGE_STATE_INCOMPLETE
147 } rbd_group_image_state_t
;
152 } rbd_group_image_spec_t
;
155 rbd_group_image_spec_t spec
;
156 rbd_group_image_state_t state
;
157 } rbd_group_image_status_t
;
165 RBD_LOCK_MODE_EXCLUSIVE
= 0,
166 RBD_LOCK_MODE_SHARED
= 1,
169 CEPH_RBD_API
void rbd_version(int *major
, int *minor
, int *extra
);
173 RBD_IMAGE_OPTION_FORMAT
= 0,
174 RBD_IMAGE_OPTION_FEATURES
= 1,
175 RBD_IMAGE_OPTION_ORDER
= 2,
176 RBD_IMAGE_OPTION_STRIPE_UNIT
= 3,
177 RBD_IMAGE_OPTION_STRIPE_COUNT
= 4,
178 RBD_IMAGE_OPTION_JOURNAL_ORDER
= 5,
179 RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH
= 6,
180 RBD_IMAGE_OPTION_JOURNAL_POOL
= 7,
181 RBD_IMAGE_OPTION_FEATURES_SET
= 8,
182 RBD_IMAGE_OPTION_FEATURES_CLEAR
= 9,
183 RBD_IMAGE_OPTION_DATA_POOL
= 10
187 RBD_TRASH_IMAGE_SOURCE_USER
= 0,
188 RBD_TRASH_IMAGE_SOURCE_MIRRORING
= 1
189 } rbd_trash_image_source_t
;
194 rbd_trash_image_source_t source
;
195 time_t deletion_time
;
196 time_t deferment_end_time
;
197 } rbd_trash_image_info_t
;
199 CEPH_RBD_API
void rbd_image_options_create(rbd_image_options_t
* opts
);
200 CEPH_RBD_API
void rbd_image_options_destroy(rbd_image_options_t opts
);
201 CEPH_RBD_API
int rbd_image_options_set_string(rbd_image_options_t opts
,
202 int optname
, const char* optval
);
203 CEPH_RBD_API
int rbd_image_options_set_uint64(rbd_image_options_t opts
,
204 int optname
, uint64_t optval
);
205 CEPH_RBD_API
int rbd_image_options_get_string(rbd_image_options_t opts
,
206 int optname
, char* optval
,
208 CEPH_RBD_API
int rbd_image_options_get_uint64(rbd_image_options_t opts
,
209 int optname
, uint64_t* optval
);
210 CEPH_RBD_API
int rbd_image_options_is_set(rbd_image_options_t opts
,
211 int optname
, bool* is_set
);
212 CEPH_RBD_API
int rbd_image_options_unset(rbd_image_options_t opts
, int optname
);
213 CEPH_RBD_API
void rbd_image_options_clear(rbd_image_options_t opts
);
214 CEPH_RBD_API
int rbd_image_options_is_empty(rbd_image_options_t opts
);
217 CEPH_RBD_API
int rbd_list(rados_ioctx_t io
, char *names
, size_t *size
);
218 CEPH_RBD_API
int rbd_create(rados_ioctx_t io
, const char *name
, uint64_t size
,
220 CEPH_RBD_API
int rbd_create2(rados_ioctx_t io
, const char *name
, uint64_t size
,
221 uint64_t features
, int *order
);
223 * create new rbd image
225 * The stripe_unit must be a factor of the object size (1 << order).
226 * The stripe_count can be one (no intra-object striping) or greater
227 * than one. The RBD_FEATURE_STRIPINGV2 must be specified if the
228 * stripe_unit != the object size and the stripe_count is != 1.
231 * @param name image name
232 * @param size image size in bytes
233 * @param features initial feature bits
234 * @param order object/block size, as a power of two (object size == 1 << order)
235 * @param stripe_unit stripe unit size, in bytes.
236 * @param stripe_count number of objects to stripe over before looping
237 * @return 0 on success, or negative error code
239 CEPH_RBD_API
int rbd_create3(rados_ioctx_t io
, const char *name
, uint64_t size
,
240 uint64_t features
, int *order
,
241 uint64_t stripe_unit
, uint64_t stripe_count
);
242 CEPH_RBD_API
int rbd_create4(rados_ioctx_t io
, const char *name
, uint64_t size
,
243 rbd_image_options_t opts
);
244 CEPH_RBD_API
int rbd_clone(rados_ioctx_t p_ioctx
, const char *p_name
,
245 const char *p_snapname
, rados_ioctx_t c_ioctx
,
246 const char *c_name
, uint64_t features
, int *c_order
);
247 CEPH_RBD_API
int rbd_clone2(rados_ioctx_t p_ioctx
, const char *p_name
,
248 const char *p_snapname
, rados_ioctx_t c_ioctx
,
249 const char *c_name
, uint64_t features
, int *c_order
,
250 uint64_t stripe_unit
, int stripe_count
);
251 CEPH_RBD_API
int rbd_clone3(rados_ioctx_t p_ioctx
, const char *p_name
,
252 const char *p_snapname
, rados_ioctx_t c_ioctx
,
253 const char *c_name
, rbd_image_options_t c_opts
);
254 CEPH_RBD_API
int rbd_remove(rados_ioctx_t io
, const char *name
);
255 CEPH_RBD_API
int rbd_remove_with_progress(rados_ioctx_t io
, const char *name
,
256 librbd_progress_fn_t cb
,
258 CEPH_RBD_API
int rbd_rename(rados_ioctx_t src_io_ctx
, const char *srcname
,
259 const char *destname
);
261 CEPH_RBD_API
int rbd_trash_move(rados_ioctx_t io
, const char *name
,
263 CEPH_RBD_API
int rbd_trash_get(rados_ioctx_t io
, const char *id
,
264 rbd_trash_image_info_t
*info
);
265 CEPH_RBD_API
void rbd_trash_get_cleanup(rbd_trash_image_info_t
*info
);
266 CEPH_RBD_API
int rbd_trash_list(rados_ioctx_t io
,
267 rbd_trash_image_info_t
*trash_entries
,
268 size_t *num_entries
);
269 CEPH_RBD_API
void rbd_trash_list_cleanup(rbd_trash_image_info_t
*trash_entries
,
271 CEPH_RBD_API
int rbd_trash_remove(rados_ioctx_t io
, const char *id
, bool force
);
272 CEPH_RBD_API
int rbd_trash_remove_with_progress(rados_ioctx_t io
, const char *id
,
273 bool force
, librbd_progress_fn_t cb
,
275 CEPH_RBD_API
int rbd_trash_restore(rados_ioctx_t io
, const char *id
,
279 CEPH_RBD_API
int rbd_mirror_mode_get(rados_ioctx_t io_ctx
,
280 rbd_mirror_mode_t
*mirror_mode
);
281 CEPH_RBD_API
int rbd_mirror_mode_set(rados_ioctx_t io_ctx
,
282 rbd_mirror_mode_t mirror_mode
);
283 CEPH_RBD_API
int rbd_mirror_peer_add(rados_ioctx_t io_ctx
,
284 char *uuid
, size_t uuid_max_length
,
285 const char *cluster_name
,
286 const char *client_name
);
287 CEPH_RBD_API
int rbd_mirror_peer_remove(rados_ioctx_t io_ctx
,
289 CEPH_RBD_API
int rbd_mirror_peer_list(rados_ioctx_t io_ctx
,
290 rbd_mirror_peer_t
*peers
, int *max_peers
);
291 CEPH_RBD_API
void rbd_mirror_peer_list_cleanup(rbd_mirror_peer_t
*peers
,
293 CEPH_RBD_API
int rbd_mirror_peer_set_client(rados_ioctx_t io_ctx
,
295 const char *client_name
);
296 CEPH_RBD_API
int rbd_mirror_peer_set_cluster(rados_ioctx_t io_ctx
,
298 const char *cluster_name
);
299 CEPH_RBD_API
int rbd_mirror_image_status_list(rados_ioctx_t io_ctx
,
300 const char *start_id
, size_t max
,
302 rbd_mirror_image_status_t
*images
,
304 CEPH_RBD_API
void rbd_mirror_image_status_list_cleanup(char **image_ids
,
305 rbd_mirror_image_status_t
*images
, size_t len
);
306 CEPH_RBD_API
int rbd_mirror_image_status_summary(rados_ioctx_t io_ctx
,
307 rbd_mirror_image_status_state_t
*states
, int *counts
, size_t *maxlen
);
309 CEPH_RBD_API
int rbd_open(rados_ioctx_t io
, const char *name
,
310 rbd_image_t
*image
, const char *snap_name
);
311 CEPH_RBD_API
int rbd_open_by_id(rados_ioctx_t io
, const char *id
,
312 rbd_image_t
*image
, const char *snap_name
);
314 CEPH_RBD_API
int rbd_aio_open(rados_ioctx_t io
, const char *name
,
315 rbd_image_t
*image
, const char *snap_name
,
317 CEPH_RBD_API
int rbd_aio_open_by_id(rados_ioctx_t io
, const char *id
,
318 rbd_image_t
*image
, const char *snap_name
,
322 * Open an image in read-only mode.
324 * This is intended for use by clients that cannot write to a block
325 * device due to cephx restrictions. There will be no watch
326 * established on the header object, since a watch is a write. This
327 * means the metadata reported about this image (parents, snapshots,
328 * size, etc.) may become stale. This should not be used for
329 * long-running operations, unless you can be sure that one of these
330 * properties changing is safe.
332 * Attempting to write to a read-only image will return -EROFS.
334 * @param io ioctx to determine the pool the image is in
335 * @param name image name
336 * @param image where to store newly opened image handle
337 * @param snap_name name of snapshot to open at, or NULL for no snapshot
338 * @returns 0 on success, negative error code on failure
340 CEPH_RBD_API
int rbd_open_read_only(rados_ioctx_t io
, const char *name
,
341 rbd_image_t
*image
, const char *snap_name
);
342 CEPH_RBD_API
int rbd_open_by_id_read_only(rados_ioctx_t io
, const char *id
,
343 rbd_image_t
*image
, const char *snap_name
);
344 CEPH_RBD_API
int rbd_aio_open_read_only(rados_ioctx_t io
, const char *name
,
345 rbd_image_t
*image
, const char *snap_name
,
347 CEPH_RBD_API
int rbd_aio_open_by_id_read_only(rados_ioctx_t io
, const char *id
,
348 rbd_image_t
*image
, const char *snap_name
,
350 CEPH_RBD_API
int rbd_close(rbd_image_t image
);
351 CEPH_RBD_API
int rbd_aio_close(rbd_image_t image
, rbd_completion_t c
);
352 CEPH_RBD_API
int rbd_resize(rbd_image_t image
, uint64_t size
);
353 CEPH_RBD_API
int rbd_resize2(rbd_image_t image
, uint64_t size
, bool allow_shrink
,
354 librbd_progress_fn_t cb
, void *cbdata
);
355 CEPH_RBD_API
int rbd_resize_with_progress(rbd_image_t image
, uint64_t size
,
356 librbd_progress_fn_t cb
, void *cbdata
);
357 CEPH_RBD_API
int rbd_stat(rbd_image_t image
, rbd_image_info_t
*info
,
359 CEPH_RBD_API
int rbd_get_old_format(rbd_image_t image
, uint8_t *old
);
360 CEPH_RBD_API
int rbd_get_size(rbd_image_t image
, uint64_t *size
);
361 CEPH_RBD_API
int rbd_get_features(rbd_image_t image
, uint64_t *features
);
362 CEPH_RBD_API
int rbd_update_features(rbd_image_t image
, uint64_t features
,
364 CEPH_RBD_API
int rbd_get_stripe_unit(rbd_image_t image
, uint64_t *stripe_unit
);
365 CEPH_RBD_API
int rbd_get_stripe_count(rbd_image_t image
,
366 uint64_t *stripe_count
);
367 CEPH_RBD_API
int rbd_get_overlap(rbd_image_t image
, uint64_t *overlap
);
368 CEPH_RBD_API
int rbd_get_id(rbd_image_t image
, char *id
, size_t id_len
);
369 CEPH_RBD_API
int rbd_get_block_name_prefix(rbd_image_t image
,
370 char *prefix
, size_t prefix_len
);
371 CEPH_RBD_API
int64_t rbd_get_data_pool_id(rbd_image_t image
);
372 CEPH_RBD_API
int rbd_get_parent_info(rbd_image_t image
,
373 char *parent_poolname
, size_t ppoolnamelen
,
374 char *parent_name
, size_t pnamelen
,
375 char *parent_snapname
,
376 size_t psnapnamelen
);
377 CEPH_RBD_API
int rbd_get_parent_info2(rbd_image_t image
,
378 char *parent_poolname
,
380 char *parent_name
, size_t pnamelen
,
381 char *parent_id
, size_t pidlen
,
382 char *parent_snapname
,
383 size_t psnapnamelen
);
384 CEPH_RBD_API
int rbd_get_flags(rbd_image_t image
, uint64_t *flags
);
385 CEPH_RBD_API
int rbd_set_image_notification(rbd_image_t image
, int fd
, int type
);
387 /* exclusive lock feature */
388 CEPH_RBD_API
int rbd_is_exclusive_lock_owner(rbd_image_t image
, int *is_owner
);
389 CEPH_RBD_API
int rbd_lock_acquire(rbd_image_t image
, rbd_lock_mode_t lock_mode
);
390 CEPH_RBD_API
int rbd_lock_release(rbd_image_t image
);
391 CEPH_RBD_API
int rbd_lock_get_owners(rbd_image_t image
,
392 rbd_lock_mode_t
*lock_mode
,
394 size_t *max_lock_owners
);
395 CEPH_RBD_API
void rbd_lock_get_owners_cleanup(char **lock_owners
,
396 size_t lock_owner_count
);
397 CEPH_RBD_API
int rbd_lock_break(rbd_image_t image
, rbd_lock_mode_t lock_mode
,
398 const char *lock_owner
);
400 /* object map feature */
401 CEPH_RBD_API
int rbd_rebuild_object_map(rbd_image_t image
,
402 librbd_progress_fn_t cb
, void *cbdata
);
404 CEPH_RBD_API
int rbd_copy(rbd_image_t image
, rados_ioctx_t dest_io_ctx
,
405 const char *destname
);
406 CEPH_RBD_API
int rbd_copy2(rbd_image_t src
, rbd_image_t dest
);
407 CEPH_RBD_API
int rbd_copy3(rbd_image_t src
, rados_ioctx_t dest_io_ctx
,
408 const char *destname
, rbd_image_options_t dest_opts
);
409 CEPH_RBD_API
int rbd_copy4(rbd_image_t src
, rados_ioctx_t dest_io_ctx
,
410 const char *destname
, rbd_image_options_t dest_opts
,
412 CEPH_RBD_API
int rbd_copy_with_progress(rbd_image_t image
, rados_ioctx_t dest_p
,
413 const char *destname
,
414 librbd_progress_fn_t cb
, void *cbdata
);
415 CEPH_RBD_API
int rbd_copy_with_progress2(rbd_image_t src
, rbd_image_t dest
,
416 librbd_progress_fn_t cb
, void *cbdata
);
417 CEPH_RBD_API
int rbd_copy_with_progress3(rbd_image_t image
,
418 rados_ioctx_t dest_p
,
419 const char *destname
,
420 rbd_image_options_t dest_opts
,
421 librbd_progress_fn_t cb
, void *cbdata
);
422 CEPH_RBD_API
int rbd_copy_with_progress4(rbd_image_t image
,
423 rados_ioctx_t dest_p
,
424 const char *destname
,
425 rbd_image_options_t dest_opts
,
426 librbd_progress_fn_t cb
, void *cbdata
,
430 CEPH_RBD_API
int rbd_snap_list(rbd_image_t image
, rbd_snap_info_t
*snaps
,
432 CEPH_RBD_API
void rbd_snap_list_end(rbd_snap_info_t
*snaps
);
433 CEPH_RBD_API
int rbd_snap_create(rbd_image_t image
, const char *snapname
);
434 CEPH_RBD_API
int rbd_snap_remove(rbd_image_t image
, const char *snapname
);
435 CEPH_RBD_API
int rbd_snap_remove2(rbd_image_t image
, const char *snap_name
, uint32_t flags
,
436 librbd_progress_fn_t cb
, void *cbdata
);
437 CEPH_RBD_API
int rbd_snap_rollback(rbd_image_t image
, const char *snapname
);
438 CEPH_RBD_API
int rbd_snap_rollback_with_progress(rbd_image_t image
,
439 const char *snapname
,
440 librbd_progress_fn_t cb
,
442 CEPH_RBD_API
int rbd_snap_rename(rbd_image_t image
, const char *snapname
,
443 const char* dstsnapsname
);
445 * Prevent a snapshot from being deleted until it is unprotected.
447 * @param snap_name which snapshot to protect
448 * @returns 0 on success, negative error code on failure
449 * @returns -EBUSY if snap is already protected
451 CEPH_RBD_API
int rbd_snap_protect(rbd_image_t image
, const char *snap_name
);
453 * Allow a snaphshot to be deleted.
455 * @param snap_name which snapshot to unprotect
456 * @returns 0 on success, negative error code on failure
457 * @returns -EINVAL if snap is not protected
459 CEPH_RBD_API
int rbd_snap_unprotect(rbd_image_t image
, const char *snap_name
);
461 * Determine whether a snapshot is protected.
463 * @param snap_name which snapshot query
464 * @param is_protected where to store the result (0 or 1)
465 * @returns 0 on success, negative error code on failure
467 CEPH_RBD_API
int rbd_snap_is_protected(rbd_image_t image
, const char *snap_name
,
470 * Get the current snapshot limit for an image. If no limit is set,
471 * UINT64_MAX is returned.
473 * @param limit pointer where the limit will be stored on success
474 * @returns 0 on success, negative error code on failure
476 CEPH_RBD_API
int rbd_snap_get_limit(rbd_image_t image
, uint64_t *limit
);
479 * Set a limit for the number of snapshots that may be taken of an image.
481 * @param limit the maximum number of snapshots allowed in the future.
482 * @returns 0 on success, negative error code on failure
484 CEPH_RBD_API
int rbd_snap_set_limit(rbd_image_t image
, uint64_t limit
);
487 * Get the timestamp of a snapshot for an image.
489 * @param snap_id the snap id of a snapshot of input image.
490 * @param timestamp the timestamp of input snapshot.
491 * @returns 0 on success, negative error code on failure
493 CEPH_RBD_API
int rbd_snap_get_timestamp(rbd_image_t image
, uint64_t snap_id
, struct timespec
*timestamp
);
495 CEPH_RBD_API
int rbd_snap_set(rbd_image_t image
, const char *snapname
);
497 CEPH_RBD_API
int rbd_flatten(rbd_image_t image
);
499 CEPH_RBD_API
int rbd_flatten_with_progress(rbd_image_t image
,
500 librbd_progress_fn_t cb
,
504 * List all images that are cloned from the image at the
505 * snapshot that is set via rbd_snap_set().
507 * This iterates over all pools, so it should be run by a user with
508 * read access to all of them. pools_len and images_len are filled in
509 * with the number of bytes put into the pools and images buffers.
511 * If the provided buffers are too short, the required lengths are
512 * still filled in, but the data is not and -ERANGE is returned.
513 * Otherwise, the buffers are filled with the pool and image names
514 * of the children, with a '\0' after each.
516 * @param image which image (and implicitly snapshot) to list clones of
517 * @param pools buffer in which to store pool names
518 * @param pools_len number of bytes in pools buffer
519 * @param images buffer in which to store image names
520 * @param images_len number of bytes in images buffer
521 * @returns number of children on success, negative error code on failure
522 * @returns -ERANGE if either buffer is too short
524 CEPH_RBD_API ssize_t
rbd_list_children(rbd_image_t image
, char *pools
,
525 size_t *pools_len
, char *images
,
529 * @defgroup librbd_h_locking Advisory Locking
531 * An rbd image may be locking exclusively, or shared, to facilitate
532 * e.g. live migration where the image may be open in two places at once.
533 * These locks are intended to guard against more than one client
534 * writing to an image without coordination. They don't need to
535 * be used for snapshots, since snapshots are read-only.
537 * Currently locks only guard against locks being acquired.
538 * They do not prevent anything else.
540 * A locker is identified by the internal rados client id of the
541 * holder and a user-defined cookie. This (client id, cookie) pair
542 * must be unique for each locker.
544 * A shared lock also has a user-defined tag associated with it. Each
545 * additional shared lock must specify the same tag or lock
546 * acquisition will fail. This can be used by e.g. groups of hosts
547 * using a clustered filesystem on top of an rbd image to make sure
548 * they're accessing the correct image.
553 * List clients that have locked the image and information about the lock.
555 * The number of bytes required in each buffer is put in the
556 * corresponding size out parameter. If any of the provided buffers
557 * are too short, -ERANGE is returned after these sizes are filled in.
559 * @param exclusive where to store whether the lock is exclusive (1) or shared (0)
560 * @param tag where to store the tag associated with the image
561 * @param tag_len number of bytes in tag buffer
562 * @param clients buffer in which locker clients are stored, separated by '\0'
563 * @param clients_len number of bytes in the clients buffer
564 * @param cookies buffer in which locker cookies are stored, separated by '\0'
565 * @param cookies_len number of bytes in the cookies buffer
566 * @param addrs buffer in which locker addresses are stored, separated by '\0'
567 * @param addrs_len number of bytes in the clients buffer
568 * @returns number of lockers on success, negative error code on failure
569 * @returns -ERANGE if any of the buffers are too short
571 CEPH_RBD_API ssize_t
rbd_list_lockers(rbd_image_t image
, int *exclusive
,
572 char *tag
, size_t *tag_len
,
573 char *clients
, size_t *clients_len
,
574 char *cookies
, size_t *cookies_len
,
575 char *addrs
, size_t *addrs_len
);
578 * Take an exclusive lock on the image.
580 * @param image the image to lock
581 * @param cookie user-defined identifier for this instance of the lock
582 * @returns 0 on success, negative error code on failure
583 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
584 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
586 CEPH_RBD_API
int rbd_lock_exclusive(rbd_image_t image
, const char *cookie
);
589 * Take a shared lock on the image.
591 * Other clients may also take a shared lock, as lock as they use the
594 * @param image the image to lock
595 * @param cookie user-defined identifier for this instance of the lock
596 * @param tag user-defined identifier for this shared use of the lock
597 * @returns 0 on success, negative error code on failure
598 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
599 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
601 CEPH_RBD_API
int rbd_lock_shared(rbd_image_t image
, const char *cookie
,
605 * Release a shared or exclusive lock on the image.
607 * @param image the image to unlock
608 * @param cookie user-defined identifier for the instance of the lock
609 * @returns 0 on success, negative error code on failure
610 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
612 CEPH_RBD_API
int rbd_unlock(rbd_image_t image
, const char *cookie
);
615 * Release a shared or exclusive lock that was taken by the specified client.
617 * @param image the image to unlock
618 * @param client the entity holding the lock (as given by rbd_list_lockers())
619 * @param cookie user-defined identifier for the instance of the lock to break
620 * @returns 0 on success, negative error code on failure
621 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
623 CEPH_RBD_API
int rbd_break_lock(rbd_image_t image
, const char *client
,
629 CEPH_RBD_API ssize_t
rbd_read(rbd_image_t image
, uint64_t ofs
, size_t len
,
632 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
634 CEPH_RBD_API ssize_t
rbd_read2(rbd_image_t image
, uint64_t ofs
, size_t len
,
635 char *buf
, int op_flags
);
636 /* DEPRECATED; use rbd_read_iterate2 */
637 CEPH_RBD_API
int64_t rbd_read_iterate(rbd_image_t image
, uint64_t ofs
, size_t len
,
638 int (*cb
)(uint64_t, size_t, const char *, void *),
642 * iterate read over an image
644 * Reads each region of the image and calls the callback. If the
645 * buffer pointer passed to the callback is NULL, the given extent is
646 * defined to be zeros (a hole). Normally the granularity for the
647 * callback is the image stripe size.
649 * @param image image to read
650 * @param ofs offset to start from
651 * @param len bytes of source image to cover
652 * @param cb callback for each region
653 * @returns 0 success, error otherwise
655 CEPH_RBD_API
int rbd_read_iterate2(rbd_image_t image
, uint64_t ofs
, uint64_t len
,
656 int (*cb
)(uint64_t, size_t, const char *, void *),
659 * get difference between two versions of an image
661 * This will return the differences between two versions of an image
662 * via a callback, which gets the offset and length and a flag
663 * indicating whether the extent exists (1), or is known/defined to
664 * be zeros (a hole, 0). If the source snapshot name is NULL, we
665 * interpret that as the beginning of time and return all allocated
666 * regions of the image. The end version is whatever is currently
667 * selected for the image handle (either a snapshot or the writeable
670 * @param fromsnapname start snapshot name, or NULL
671 * @param ofs start offset
672 * @param len len in bytes of region to report on
673 * @param include_parent 1 if full history diff should include parent
674 * @param whole_object 1 if diff extents should cover whole object
675 * @param cb callback to call for each allocated region
676 * @param arg argument to pass to the callback
677 * @returns 0 on success, or negative error code on error
679 CEPH_RBD_API
int rbd_diff_iterate(rbd_image_t image
,
680 const char *fromsnapname
,
681 uint64_t ofs
, uint64_t len
,
682 int (*cb
)(uint64_t, size_t, int, void *),
684 CEPH_RBD_API
int rbd_diff_iterate2(rbd_image_t image
,
685 const char *fromsnapname
,
686 uint64_t ofs
, uint64_t len
,
687 uint8_t include_parent
, uint8_t whole_object
,
688 int (*cb
)(uint64_t, size_t, int, void *),
690 CEPH_RBD_API ssize_t
rbd_write(rbd_image_t image
, uint64_t ofs
, size_t len
,
693 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
695 CEPH_RBD_API ssize_t
rbd_write2(rbd_image_t image
, uint64_t ofs
, size_t len
,
696 const char *buf
, int op_flags
);
697 CEPH_RBD_API
int rbd_discard(rbd_image_t image
, uint64_t ofs
, uint64_t len
);
698 CEPH_RBD_API ssize_t
rbd_writesame(rbd_image_t image
, uint64_t ofs
, size_t len
,
699 const char *buf
, size_t data_len
, int op_flags
);
700 CEPH_RBD_API
int rbd_aio_write(rbd_image_t image
, uint64_t off
, size_t len
,
701 const char *buf
, rbd_completion_t c
);
704 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
706 CEPH_RBD_API
int rbd_aio_write2(rbd_image_t image
, uint64_t off
, size_t len
,
707 const char *buf
, rbd_completion_t c
,
709 CEPH_RBD_API
int rbd_aio_writev(rbd_image_t image
, const struct iovec
*iov
,
710 int iovcnt
, uint64_t off
, rbd_completion_t c
);
711 CEPH_RBD_API
int rbd_aio_read(rbd_image_t image
, uint64_t off
, size_t len
,
712 char *buf
, rbd_completion_t c
);
714 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
716 CEPH_RBD_API
int rbd_aio_read2(rbd_image_t image
, uint64_t off
, size_t len
,
717 char *buf
, rbd_completion_t c
, int op_flags
);
718 CEPH_RBD_API
int rbd_aio_readv(rbd_image_t image
, const struct iovec
*iov
,
719 int iovcnt
, uint64_t off
, rbd_completion_t c
);
720 CEPH_RBD_API
int rbd_aio_discard(rbd_image_t image
, uint64_t off
, uint64_t len
,
722 CEPH_RBD_API
int rbd_aio_writesame(rbd_image_t image
, uint64_t off
, size_t len
,
723 const char *buf
, size_t data_len
,
724 rbd_completion_t c
, int op_flags
);
726 CEPH_RBD_API
int rbd_aio_create_completion(void *cb_arg
,
727 rbd_callback_t complete_cb
,
728 rbd_completion_t
*c
);
729 CEPH_RBD_API
int rbd_aio_is_complete(rbd_completion_t c
);
730 CEPH_RBD_API
int rbd_aio_wait_for_complete(rbd_completion_t c
);
731 CEPH_RBD_API ssize_t
rbd_aio_get_return_value(rbd_completion_t c
);
732 CEPH_RBD_API
void *rbd_aio_get_arg(rbd_completion_t c
);
733 CEPH_RBD_API
void rbd_aio_release(rbd_completion_t c
);
734 CEPH_RBD_API
int rbd_flush(rbd_image_t image
);
736 * Start a flush if caching is enabled. Get a callback when
737 * the currently pending writes are on disk.
739 * @param image the image to flush writes to
740 * @param c what to call when flushing is complete
741 * @returns 0 on success, negative error code on failure
743 CEPH_RBD_API
int rbd_aio_flush(rbd_image_t image
, rbd_completion_t c
);
746 * Drop any cached data for an image
748 * @param image the image to invalidate cached data for
749 * @returns 0 on success, negative error code on failure
751 CEPH_RBD_API
int rbd_invalidate_cache(rbd_image_t image
);
753 CEPH_RBD_API
int rbd_poll_io_events(rbd_image_t image
, rbd_completion_t
*comps
, int numcomp
);
755 CEPH_RBD_API
int rbd_metadata_get(rbd_image_t image
, const char *key
, char *value
, size_t *val_len
);
756 CEPH_RBD_API
int rbd_metadata_set(rbd_image_t image
, const char *key
, const char *value
);
757 CEPH_RBD_API
int rbd_metadata_remove(rbd_image_t image
, const char *key
);
759 * List all metadatas associated with this image.
761 * This iterates over all metadatas, key_len and val_len are filled in
762 * with the number of bytes put into the keys and values buffers.
764 * If the provided buffers are too short, the required lengths are
765 * still filled in, but the data is not and -ERANGE is returned.
766 * Otherwise, the buffers are filled with the keys and values
767 * of the image, with a '\0' after each.
769 * @param image which image (and implicitly snapshot) to list clones of
770 * @param start_after which name to begin listing after
771 * (use the empty string to start at the beginning)
772 * @param max the maximum number of names to lis(if 0 means no limit)
773 * @param keys buffer in which to store pool names
774 * @param keys_len number of bytes in pools buffer
775 * @param values buffer in which to store image names
776 * @param vals_len number of bytes in images buffer
777 * @returns number of children on success, negative error code on failure
778 * @returns -ERANGE if either buffer is too short
780 CEPH_RBD_API
int rbd_metadata_list(rbd_image_t image
, const char *start
, uint64_t max
,
781 char *keys
, size_t *key_len
, char *values
, size_t *vals_len
);
783 // RBD image mirroring support functions
784 CEPH_RBD_API
int rbd_mirror_image_enable(rbd_image_t image
);
785 CEPH_RBD_API
int rbd_mirror_image_disable(rbd_image_t image
, bool force
);
786 CEPH_RBD_API
int rbd_mirror_image_promote(rbd_image_t image
, bool force
);
787 CEPH_RBD_API
int rbd_mirror_image_demote(rbd_image_t image
);
788 CEPH_RBD_API
int rbd_mirror_image_resync(rbd_image_t image
);
789 CEPH_RBD_API
int rbd_mirror_image_get_info(rbd_image_t image
,
790 rbd_mirror_image_info_t
*mirror_image_info
,
792 CEPH_RBD_API
int rbd_mirror_image_get_status(rbd_image_t image
,
793 rbd_mirror_image_status_t
*mirror_image_status
,
795 CEPH_RBD_API
int rbd_aio_mirror_image_promote(rbd_image_t image
, bool force
,
797 CEPH_RBD_API
int rbd_aio_mirror_image_demote(rbd_image_t image
,
799 CEPH_RBD_API
int rbd_aio_mirror_image_get_info(rbd_image_t image
,
800 rbd_mirror_image_info_t
*mirror_image_info
,
803 CEPH_RBD_API
int rbd_aio_mirror_image_get_status(rbd_image_t image
,
804 rbd_mirror_image_status_t
*mirror_image_status
,
808 // RBD consistency groups support functions
809 CEPH_RBD_API
int rbd_group_create(rados_ioctx_t p
, const char *name
);
810 CEPH_RBD_API
int rbd_group_remove(rados_ioctx_t p
, const char *name
);
811 CEPH_RBD_API
int rbd_group_list(rados_ioctx_t p
, char *names
, size_t *size
);
814 * Register an image metadata change watcher.
816 * @param image the image to watch
817 * @param handle where to store the internal id assigned to this watch
818 * @param watch_cb what to do when a notify is received on this image
819 * @param arg opaque value to pass to the callback
820 * @returns 0 on success, negative error code on failure
822 CEPH_RBD_API
int rbd_update_watch(rbd_image_t image
, uint64_t *handle
,
823 rbd_update_callback_t watch_cb
, void *arg
);
826 * Unregister an image watcher.
828 * @param image the image to unwatch
829 * @param handle which watch to unregister
830 * @returns 0 on success, negative error code on failure
832 CEPH_RBD_API
int rbd_update_unwatch(rbd_image_t image
, uint64_t handle
);
835 CEPH_RBD_API
int rbd_group_image_add(
836 rados_ioctx_t group_p
, const char *group_name
,
837 rados_ioctx_t image_p
, const char *image_name
);
838 CEPH_RBD_API
int rbd_group_image_remove(
839 rados_ioctx_t group_p
, const char *group_name
,
840 rados_ioctx_t image_p
, const char *image_name
);
841 CEPH_RBD_API
int rbd_group_image_remove_by_id(
842 rados_ioctx_t group_p
, const char *group_name
,
843 rados_ioctx_t image_p
, const char *image_id
);
844 CEPH_RBD_API
int rbd_group_image_list(
845 rados_ioctx_t group_p
, const char *group_name
,
846 rbd_group_image_status_t
*images
,
848 CEPH_RBD_API
int rbd_image_get_group(rados_ioctx_t image_p
,
849 const char *image_name
,
850 rbd_group_spec_t
*group_spec
);
851 CEPH_RBD_API
void rbd_group_spec_cleanup(rbd_group_spec_t
*group_spec
);
852 CEPH_RBD_API
void rbd_group_image_status_cleanup(
853 rbd_group_image_status_t
*image
855 CEPH_RBD_API
void rbd_group_image_status_list_cleanup(
856 rbd_group_image_status_t
*images
,