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_COMPARE_AND_WRITE 1
45 #define LIBRBD_SUPPORTS_LOCKING 1
46 #define LIBRBD_SUPPORTS_INVALIDATE 1
47 #define LIBRBD_SUPPORTS_IOVEC 1
48 #define LIBRBD_SUPPORTS_WATCH 0
49 #define LIBRBD_SUPPORTS_WRITESAME 1
52 #define CEPH_RBD_API __attribute__ ((visibility ("default")))
57 #define RBD_FLAG_OBJECT_MAP_INVALID (1<<0)
58 #define RBD_FLAG_FAST_DIFF_INVALID (1<<1)
60 typedef void *rbd_snap_t
;
61 typedef void *rbd_image_t
;
62 typedef void *rbd_image_options_t
;
64 typedef void *rbd_completion_t
;
65 typedef void (*rbd_callback_t
)(rbd_completion_t cb
, void *arg
);
67 typedef int (*librbd_progress_fn_t
)(uint64_t offset
, uint64_t total
, void *ptr
);
69 typedef void (*rbd_update_callback_t
)(void *arg
);
77 #define RBD_MAX_IMAGE_NAME_SIZE 96
78 #define RBD_MAX_BLOCK_NAME_SIZE 24
80 #define RBD_SNAP_REMOVE_UNPROTECT 1 << 0
81 #define RBD_SNAP_REMOVE_FLATTEN 1 << 1
82 #define RBD_SNAP_REMOVE_FORCE (RBD_SNAP_REMOVE_UNPROTECT | RBD_SNAP_REMOVE_FLATTEN)
85 * These types used to in set_image_notification to indicate the type of event
90 EVENT_TYPE_EVENTFD
= 2
98 char block_name_prefix
[RBD_MAX_BLOCK_NAME_SIZE
]; /* deprecated */
99 int64_t parent_pool
; /* deprecated */
100 char parent_name
[RBD_MAX_IMAGE_NAME_SIZE
]; /* deprecated */
104 RBD_MIRROR_MODE_DISABLED
, /* mirroring is disabled */
105 RBD_MIRROR_MODE_IMAGE
, /* mirroring enabled on a per-image basis */
106 RBD_MIRROR_MODE_POOL
/* mirroring enabled on all journaled images */
116 RBD_MIRROR_IMAGE_DISABLING
= 0,
117 RBD_MIRROR_IMAGE_ENABLED
= 1,
118 RBD_MIRROR_IMAGE_DISABLED
= 2
119 } rbd_mirror_image_state_t
;
123 rbd_mirror_image_state_t state
;
125 } rbd_mirror_image_info_t
;
128 MIRROR_IMAGE_STATUS_STATE_UNKNOWN
= 0,
129 MIRROR_IMAGE_STATUS_STATE_ERROR
= 1,
130 MIRROR_IMAGE_STATUS_STATE_SYNCING
= 2,
131 MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY
= 3,
132 MIRROR_IMAGE_STATUS_STATE_REPLAYING
= 4,
133 MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY
= 5,
134 MIRROR_IMAGE_STATUS_STATE_STOPPED
= 6,
135 } rbd_mirror_image_status_state_t
;
139 rbd_mirror_image_info_t info
;
140 rbd_mirror_image_status_state_t state
;
144 } rbd_mirror_image_status_t
;
147 RBD_LOCK_MODE_EXCLUSIVE
= 0,
148 RBD_LOCK_MODE_SHARED
= 1,
151 CEPH_RBD_API
void rbd_version(int *major
, int *minor
, int *extra
);
155 RBD_IMAGE_OPTION_FORMAT
= 0,
156 RBD_IMAGE_OPTION_FEATURES
= 1,
157 RBD_IMAGE_OPTION_ORDER
= 2,
158 RBD_IMAGE_OPTION_STRIPE_UNIT
= 3,
159 RBD_IMAGE_OPTION_STRIPE_COUNT
= 4,
160 RBD_IMAGE_OPTION_JOURNAL_ORDER
= 5,
161 RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH
= 6,
162 RBD_IMAGE_OPTION_JOURNAL_POOL
= 7,
163 RBD_IMAGE_OPTION_FEATURES_SET
= 8,
164 RBD_IMAGE_OPTION_FEATURES_CLEAR
= 9,
165 RBD_IMAGE_OPTION_DATA_POOL
= 10
169 RBD_TRASH_IMAGE_SOURCE_USER
= 0,
170 RBD_TRASH_IMAGE_SOURCE_MIRRORING
= 1
171 } rbd_trash_image_source_t
;
176 rbd_trash_image_source_t source
;
177 time_t deletion_time
;
178 time_t deferment_end_time
;
179 } rbd_trash_image_info_t
;
181 CEPH_RBD_API
void rbd_image_options_create(rbd_image_options_t
* opts
);
182 CEPH_RBD_API
void rbd_image_options_destroy(rbd_image_options_t opts
);
183 CEPH_RBD_API
int rbd_image_options_set_string(rbd_image_options_t opts
,
184 int optname
, const char* optval
);
185 CEPH_RBD_API
int rbd_image_options_set_uint64(rbd_image_options_t opts
,
186 int optname
, uint64_t optval
);
187 CEPH_RBD_API
int rbd_image_options_get_string(rbd_image_options_t opts
,
188 int optname
, char* optval
,
190 CEPH_RBD_API
int rbd_image_options_get_uint64(rbd_image_options_t opts
,
191 int optname
, uint64_t* optval
);
192 CEPH_RBD_API
int rbd_image_options_is_set(rbd_image_options_t opts
,
193 int optname
, bool* is_set
);
194 CEPH_RBD_API
int rbd_image_options_unset(rbd_image_options_t opts
, int optname
);
195 CEPH_RBD_API
void rbd_image_options_clear(rbd_image_options_t opts
);
196 CEPH_RBD_API
int rbd_image_options_is_empty(rbd_image_options_t opts
);
199 CEPH_RBD_API
int rbd_list(rados_ioctx_t io
, char *names
, size_t *size
);
200 CEPH_RBD_API
int rbd_create(rados_ioctx_t io
, const char *name
, uint64_t size
,
202 CEPH_RBD_API
int rbd_create2(rados_ioctx_t io
, const char *name
, uint64_t size
,
203 uint64_t features
, int *order
);
205 * create new rbd image
207 * The stripe_unit must be a factor of the object size (1 << order).
208 * The stripe_count can be one (no intra-object striping) or greater
209 * than one. The RBD_FEATURE_STRIPINGV2 must be specified if the
210 * stripe_unit != the object size and the stripe_count is != 1.
213 * @param name image name
214 * @param size image size in bytes
215 * @param features initial feature bits
216 * @param order object/block size, as a power of two (object size == 1 << order)
217 * @param stripe_unit stripe unit size, in bytes.
218 * @param stripe_count number of objects to stripe over before looping
219 * @return 0 on success, or negative error code
221 CEPH_RBD_API
int rbd_create3(rados_ioctx_t io
, const char *name
, uint64_t size
,
222 uint64_t features
, int *order
,
223 uint64_t stripe_unit
, uint64_t stripe_count
);
224 CEPH_RBD_API
int rbd_create4(rados_ioctx_t io
, const char *name
, uint64_t size
,
225 rbd_image_options_t opts
);
226 CEPH_RBD_API
int rbd_clone(rados_ioctx_t p_ioctx
, const char *p_name
,
227 const char *p_snapname
, rados_ioctx_t c_ioctx
,
228 const char *c_name
, uint64_t features
, int *c_order
);
229 CEPH_RBD_API
int rbd_clone2(rados_ioctx_t p_ioctx
, const char *p_name
,
230 const char *p_snapname
, rados_ioctx_t c_ioctx
,
231 const char *c_name
, uint64_t features
, int *c_order
,
232 uint64_t stripe_unit
, int stripe_count
);
233 CEPH_RBD_API
int rbd_clone3(rados_ioctx_t p_ioctx
, const char *p_name
,
234 const char *p_snapname
, rados_ioctx_t c_ioctx
,
235 const char *c_name
, rbd_image_options_t c_opts
);
236 CEPH_RBD_API
int rbd_remove(rados_ioctx_t io
, const char *name
);
237 CEPH_RBD_API
int rbd_remove_with_progress(rados_ioctx_t io
, const char *name
,
238 librbd_progress_fn_t cb
,
240 CEPH_RBD_API
int rbd_rename(rados_ioctx_t src_io_ctx
, const char *srcname
,
241 const char *destname
);
243 CEPH_RBD_API
int rbd_trash_move(rados_ioctx_t io
, const char *name
,
245 CEPH_RBD_API
int rbd_trash_get(rados_ioctx_t io
, const char *id
,
246 rbd_trash_image_info_t
*info
);
247 CEPH_RBD_API
void rbd_trash_get_cleanup(rbd_trash_image_info_t
*info
);
248 CEPH_RBD_API
int rbd_trash_list(rados_ioctx_t io
,
249 rbd_trash_image_info_t
*trash_entries
,
250 size_t *num_entries
);
251 CEPH_RBD_API
void rbd_trash_list_cleanup(rbd_trash_image_info_t
*trash_entries
,
253 CEPH_RBD_API
int rbd_trash_remove(rados_ioctx_t io
, const char *id
, bool force
);
254 CEPH_RBD_API
int rbd_trash_remove_with_progress(rados_ioctx_t io
, const char *id
,
255 bool force
, librbd_progress_fn_t cb
,
257 CEPH_RBD_API
int rbd_trash_restore(rados_ioctx_t io
, const char *id
,
261 CEPH_RBD_API
int rbd_mirror_mode_get(rados_ioctx_t io_ctx
,
262 rbd_mirror_mode_t
*mirror_mode
);
263 CEPH_RBD_API
int rbd_mirror_mode_set(rados_ioctx_t io_ctx
,
264 rbd_mirror_mode_t mirror_mode
);
265 CEPH_RBD_API
int rbd_mirror_peer_add(rados_ioctx_t io_ctx
,
266 char *uuid
, size_t uuid_max_length
,
267 const char *cluster_name
,
268 const char *client_name
);
269 CEPH_RBD_API
int rbd_mirror_peer_remove(rados_ioctx_t io_ctx
,
271 CEPH_RBD_API
int rbd_mirror_peer_list(rados_ioctx_t io_ctx
,
272 rbd_mirror_peer_t
*peers
, int *max_peers
);
273 CEPH_RBD_API
void rbd_mirror_peer_list_cleanup(rbd_mirror_peer_t
*peers
,
275 CEPH_RBD_API
int rbd_mirror_peer_set_client(rados_ioctx_t io_ctx
,
277 const char *client_name
);
278 CEPH_RBD_API
int rbd_mirror_peer_set_cluster(rados_ioctx_t io_ctx
,
280 const char *cluster_name
);
281 CEPH_RBD_API
int rbd_mirror_image_status_list(rados_ioctx_t io_ctx
,
282 const char *start_id
, size_t max
,
284 rbd_mirror_image_status_t
*images
,
286 CEPH_RBD_API
void rbd_mirror_image_status_list_cleanup(char **image_ids
,
287 rbd_mirror_image_status_t
*images
, size_t len
);
288 CEPH_RBD_API
int rbd_mirror_image_status_summary(rados_ioctx_t io_ctx
,
289 rbd_mirror_image_status_state_t
*states
, int *counts
, size_t *maxlen
);
291 CEPH_RBD_API
int rbd_open(rados_ioctx_t io
, const char *name
,
292 rbd_image_t
*image
, const char *snap_name
);
293 CEPH_RBD_API
int rbd_open_by_id(rados_ioctx_t io
, const char *id
,
294 rbd_image_t
*image
, const char *snap_name
);
296 CEPH_RBD_API
int rbd_aio_open(rados_ioctx_t io
, const char *name
,
297 rbd_image_t
*image
, const char *snap_name
,
299 CEPH_RBD_API
int rbd_aio_open_by_id(rados_ioctx_t io
, const char *id
,
300 rbd_image_t
*image
, const char *snap_name
,
304 * Open an image in read-only mode.
306 * This is intended for use by clients that cannot write to a block
307 * device due to cephx restrictions. There will be no watch
308 * established on the header object, since a watch is a write. This
309 * means the metadata reported about this image (parents, snapshots,
310 * size, etc.) may become stale. This should not be used for
311 * long-running operations, unless you can be sure that one of these
312 * properties changing is safe.
314 * Attempting to write to a read-only image will return -EROFS.
316 * @param io ioctx to determine the pool the image is in
317 * @param name image name
318 * @param image where to store newly opened image handle
319 * @param snap_name name of snapshot to open at, or NULL for no snapshot
320 * @returns 0 on success, negative error code on failure
322 CEPH_RBD_API
int rbd_open_read_only(rados_ioctx_t io
, const char *name
,
323 rbd_image_t
*image
, const char *snap_name
);
324 CEPH_RBD_API
int rbd_open_by_id_read_only(rados_ioctx_t io
, const char *id
,
325 rbd_image_t
*image
, const char *snap_name
);
326 CEPH_RBD_API
int rbd_aio_open_read_only(rados_ioctx_t io
, const char *name
,
327 rbd_image_t
*image
, const char *snap_name
,
329 CEPH_RBD_API
int rbd_aio_open_by_id_read_only(rados_ioctx_t io
, const char *id
,
330 rbd_image_t
*image
, const char *snap_name
,
332 CEPH_RBD_API
int rbd_close(rbd_image_t image
);
333 CEPH_RBD_API
int rbd_aio_close(rbd_image_t image
, rbd_completion_t c
);
334 CEPH_RBD_API
int rbd_resize(rbd_image_t image
, uint64_t size
);
335 CEPH_RBD_API
int rbd_resize2(rbd_image_t image
, uint64_t size
, bool allow_shrink
,
336 librbd_progress_fn_t cb
, void *cbdata
);
337 CEPH_RBD_API
int rbd_resize_with_progress(rbd_image_t image
, uint64_t size
,
338 librbd_progress_fn_t cb
, void *cbdata
);
339 CEPH_RBD_API
int rbd_stat(rbd_image_t image
, rbd_image_info_t
*info
,
341 CEPH_RBD_API
int rbd_get_old_format(rbd_image_t image
, uint8_t *old
);
342 CEPH_RBD_API
int rbd_get_size(rbd_image_t image
, uint64_t *size
);
343 CEPH_RBD_API
int rbd_get_features(rbd_image_t image
, uint64_t *features
);
344 CEPH_RBD_API
int rbd_update_features(rbd_image_t image
, uint64_t features
,
346 CEPH_RBD_API
int rbd_get_stripe_unit(rbd_image_t image
, uint64_t *stripe_unit
);
347 CEPH_RBD_API
int rbd_get_stripe_count(rbd_image_t image
,
348 uint64_t *stripe_count
);
350 CEPH_RBD_API
int rbd_get_create_timestamp(rbd_image_t image
,
351 struct timespec
*timestamp
);
353 CEPH_RBD_API
int rbd_get_overlap(rbd_image_t image
, uint64_t *overlap
);
354 CEPH_RBD_API
int rbd_get_id(rbd_image_t image
, char *id
, size_t id_len
);
355 CEPH_RBD_API
int rbd_get_block_name_prefix(rbd_image_t image
,
356 char *prefix
, size_t prefix_len
);
357 CEPH_RBD_API
int64_t rbd_get_data_pool_id(rbd_image_t image
);
358 CEPH_RBD_API
int rbd_get_parent_info(rbd_image_t image
,
359 char *parent_poolname
, size_t ppoolnamelen
,
360 char *parent_name
, size_t pnamelen
,
361 char *parent_snapname
,
362 size_t psnapnamelen
);
363 CEPH_RBD_API
int rbd_get_parent_info2(rbd_image_t image
,
364 char *parent_poolname
,
366 char *parent_name
, size_t pnamelen
,
367 char *parent_id
, size_t pidlen
,
368 char *parent_snapname
,
369 size_t psnapnamelen
);
370 CEPH_RBD_API
int rbd_get_flags(rbd_image_t image
, uint64_t *flags
);
371 CEPH_RBD_API
int rbd_set_image_notification(rbd_image_t image
, int fd
, int type
);
373 /* exclusive lock feature */
374 CEPH_RBD_API
int rbd_is_exclusive_lock_owner(rbd_image_t image
, int *is_owner
);
375 CEPH_RBD_API
int rbd_lock_acquire(rbd_image_t image
, rbd_lock_mode_t lock_mode
);
376 CEPH_RBD_API
int rbd_lock_release(rbd_image_t image
);
377 CEPH_RBD_API
int rbd_lock_get_owners(rbd_image_t image
,
378 rbd_lock_mode_t
*lock_mode
,
380 size_t *max_lock_owners
);
381 CEPH_RBD_API
void rbd_lock_get_owners_cleanup(char **lock_owners
,
382 size_t lock_owner_count
);
383 CEPH_RBD_API
int rbd_lock_break(rbd_image_t image
, rbd_lock_mode_t lock_mode
,
384 const char *lock_owner
);
386 /* object map feature */
387 CEPH_RBD_API
int rbd_rebuild_object_map(rbd_image_t image
,
388 librbd_progress_fn_t cb
, void *cbdata
);
390 CEPH_RBD_API
int rbd_copy(rbd_image_t image
, rados_ioctx_t dest_io_ctx
,
391 const char *destname
);
392 CEPH_RBD_API
int rbd_copy2(rbd_image_t src
, rbd_image_t dest
);
393 CEPH_RBD_API
int rbd_copy3(rbd_image_t src
, rados_ioctx_t dest_io_ctx
,
394 const char *destname
, rbd_image_options_t dest_opts
);
395 CEPH_RBD_API
int rbd_copy4(rbd_image_t src
, rados_ioctx_t dest_io_ctx
,
396 const char *destname
, rbd_image_options_t dest_opts
,
398 CEPH_RBD_API
int rbd_copy_with_progress(rbd_image_t image
, rados_ioctx_t dest_p
,
399 const char *destname
,
400 librbd_progress_fn_t cb
, void *cbdata
);
401 CEPH_RBD_API
int rbd_copy_with_progress2(rbd_image_t src
, rbd_image_t dest
,
402 librbd_progress_fn_t cb
, void *cbdata
);
403 CEPH_RBD_API
int rbd_copy_with_progress3(rbd_image_t image
,
404 rados_ioctx_t dest_p
,
405 const char *destname
,
406 rbd_image_options_t dest_opts
,
407 librbd_progress_fn_t cb
, void *cbdata
);
408 CEPH_RBD_API
int rbd_copy_with_progress4(rbd_image_t image
,
409 rados_ioctx_t dest_p
,
410 const char *destname
,
411 rbd_image_options_t dest_opts
,
412 librbd_progress_fn_t cb
, void *cbdata
,
416 CEPH_RBD_API
int rbd_snap_list(rbd_image_t image
, rbd_snap_info_t
*snaps
,
418 CEPH_RBD_API
void rbd_snap_list_end(rbd_snap_info_t
*snaps
);
419 CEPH_RBD_API
int rbd_snap_create(rbd_image_t image
, const char *snapname
);
420 CEPH_RBD_API
int rbd_snap_remove(rbd_image_t image
, const char *snapname
);
421 CEPH_RBD_API
int rbd_snap_remove2(rbd_image_t image
, const char *snap_name
, uint32_t flags
,
422 librbd_progress_fn_t cb
, void *cbdata
);
423 CEPH_RBD_API
int rbd_snap_rollback(rbd_image_t image
, const char *snapname
);
424 CEPH_RBD_API
int rbd_snap_rollback_with_progress(rbd_image_t image
,
425 const char *snapname
,
426 librbd_progress_fn_t cb
,
428 CEPH_RBD_API
int rbd_snap_rename(rbd_image_t image
, const char *snapname
,
429 const char* dstsnapsname
);
431 * Prevent a snapshot from being deleted until it is unprotected.
433 * @param snap_name which snapshot to protect
434 * @returns 0 on success, negative error code on failure
435 * @returns -EBUSY if snap is already protected
437 CEPH_RBD_API
int rbd_snap_protect(rbd_image_t image
, const char *snap_name
);
439 * Allow a snaphshot to be deleted.
441 * @param snap_name which snapshot to unprotect
442 * @returns 0 on success, negative error code on failure
443 * @returns -EINVAL if snap is not protected
445 CEPH_RBD_API
int rbd_snap_unprotect(rbd_image_t image
, const char *snap_name
);
447 * Determine whether a snapshot is protected.
449 * @param snap_name which snapshot query
450 * @param is_protected where to store the result (0 or 1)
451 * @returns 0 on success, negative error code on failure
453 CEPH_RBD_API
int rbd_snap_is_protected(rbd_image_t image
, const char *snap_name
,
456 * Get the current snapshot limit for an image. If no limit is set,
457 * UINT64_MAX is returned.
459 * @param limit pointer where the limit will be stored on success
460 * @returns 0 on success, negative error code on failure
462 CEPH_RBD_API
int rbd_snap_get_limit(rbd_image_t image
, uint64_t *limit
);
465 * Set a limit for the number of snapshots that may be taken of an image.
467 * @param limit the maximum number of snapshots allowed in the future.
468 * @returns 0 on success, negative error code on failure
470 CEPH_RBD_API
int rbd_snap_set_limit(rbd_image_t image
, uint64_t limit
);
473 * Get the timestamp of a snapshot for an image.
475 * @param snap_id the snap id of a snapshot of input image.
476 * @param timestamp the timestamp of input snapshot.
477 * @returns 0 on success, negative error code on failure
479 CEPH_RBD_API
int rbd_snap_get_timestamp(rbd_image_t image
, uint64_t snap_id
, struct timespec
*timestamp
);
481 CEPH_RBD_API
int rbd_snap_set(rbd_image_t image
, const char *snapname
);
483 CEPH_RBD_API
int rbd_flatten(rbd_image_t image
);
485 CEPH_RBD_API
int rbd_flatten_with_progress(rbd_image_t image
,
486 librbd_progress_fn_t cb
,
490 * List all images that are cloned from the image at the
491 * snapshot that is set via rbd_snap_set().
493 * This iterates over all pools, so it should be run by a user with
494 * read access to all of them. pools_len and images_len are filled in
495 * with the number of bytes put into the pools and images buffers.
497 * If the provided buffers are too short, the required lengths are
498 * still filled in, but the data is not and -ERANGE is returned.
499 * Otherwise, the buffers are filled with the pool and image names
500 * of the children, with a '\0' after each.
502 * @param image which image (and implicitly snapshot) to list clones of
503 * @param pools buffer in which to store pool names
504 * @param pools_len number of bytes in pools buffer
505 * @param images buffer in which to store image names
506 * @param images_len number of bytes in images buffer
507 * @returns number of children on success, negative error code on failure
508 * @returns -ERANGE if either buffer is too short
510 CEPH_RBD_API ssize_t
rbd_list_children(rbd_image_t image
, char *pools
,
511 size_t *pools_len
, char *images
,
515 * @defgroup librbd_h_locking Advisory Locking
517 * An rbd image may be locking exclusively, or shared, to facilitate
518 * e.g. live migration where the image may be open in two places at once.
519 * These locks are intended to guard against more than one client
520 * writing to an image without coordination. They don't need to
521 * be used for snapshots, since snapshots are read-only.
523 * Currently locks only guard against locks being acquired.
524 * They do not prevent anything else.
526 * A locker is identified by the internal rados client id of the
527 * holder and a user-defined cookie. This (client id, cookie) pair
528 * must be unique for each locker.
530 * A shared lock also has a user-defined tag associated with it. Each
531 * additional shared lock must specify the same tag or lock
532 * acquisition will fail. This can be used by e.g. groups of hosts
533 * using a clustered filesystem on top of an rbd image to make sure
534 * they're accessing the correct image.
539 * List clients that have locked the image and information about the lock.
541 * The number of bytes required in each buffer is put in the
542 * corresponding size out parameter. If any of the provided buffers
543 * are too short, -ERANGE is returned after these sizes are filled in.
545 * @param exclusive where to store whether the lock is exclusive (1) or shared (0)
546 * @param tag where to store the tag associated with the image
547 * @param tag_len number of bytes in tag buffer
548 * @param clients buffer in which locker clients are stored, separated by '\0'
549 * @param clients_len number of bytes in the clients buffer
550 * @param cookies buffer in which locker cookies are stored, separated by '\0'
551 * @param cookies_len number of bytes in the cookies buffer
552 * @param addrs buffer in which locker addresses are stored, separated by '\0'
553 * @param addrs_len number of bytes in the clients buffer
554 * @returns number of lockers on success, negative error code on failure
555 * @returns -ERANGE if any of the buffers are too short
557 CEPH_RBD_API ssize_t
rbd_list_lockers(rbd_image_t image
, int *exclusive
,
558 char *tag
, size_t *tag_len
,
559 char *clients
, size_t *clients_len
,
560 char *cookies
, size_t *cookies_len
,
561 char *addrs
, size_t *addrs_len
);
564 * Take an exclusive lock on the image.
566 * @param image the image to lock
567 * @param cookie user-defined identifier for this instance of the lock
568 * @returns 0 on success, negative error code on failure
569 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
570 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
572 CEPH_RBD_API
int rbd_lock_exclusive(rbd_image_t image
, const char *cookie
);
575 * Take a shared lock on the image.
577 * Other clients may also take a shared lock, as lock as they use the
580 * @param image the image to lock
581 * @param cookie user-defined identifier for this instance of the lock
582 * @param tag user-defined identifier for this shared use of the lock
583 * @returns 0 on success, negative error code on failure
584 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
585 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
587 CEPH_RBD_API
int rbd_lock_shared(rbd_image_t image
, const char *cookie
,
591 * Release a shared or exclusive lock on the image.
593 * @param image the image to unlock
594 * @param cookie user-defined identifier for the instance of the lock
595 * @returns 0 on success, negative error code on failure
596 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
598 CEPH_RBD_API
int rbd_unlock(rbd_image_t image
, const char *cookie
);
601 * Release a shared or exclusive lock that was taken by the specified client.
603 * @param image the image to unlock
604 * @param client the entity holding the lock (as given by rbd_list_lockers())
605 * @param cookie user-defined identifier for the instance of the lock to break
606 * @returns 0 on success, negative error code on failure
607 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
609 CEPH_RBD_API
int rbd_break_lock(rbd_image_t image
, const char *client
,
615 CEPH_RBD_API ssize_t
rbd_read(rbd_image_t image
, uint64_t ofs
, size_t len
,
618 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
620 CEPH_RBD_API ssize_t
rbd_read2(rbd_image_t image
, uint64_t ofs
, size_t len
,
621 char *buf
, int op_flags
);
622 /* DEPRECATED; use rbd_read_iterate2 */
623 CEPH_RBD_API
int64_t rbd_read_iterate(rbd_image_t image
, uint64_t ofs
, size_t len
,
624 int (*cb
)(uint64_t, size_t, const char *, void *),
628 * iterate read over an image
630 * Reads each region of the image and calls the callback. If the
631 * buffer pointer passed to the callback is NULL, the given extent is
632 * defined to be zeros (a hole). Normally the granularity for the
633 * callback is the image stripe size.
635 * @param image image to read
636 * @param ofs offset to start from
637 * @param len bytes of source image to cover
638 * @param cb callback for each region
639 * @returns 0 success, error otherwise
641 CEPH_RBD_API
int rbd_read_iterate2(rbd_image_t image
, uint64_t ofs
, uint64_t len
,
642 int (*cb
)(uint64_t, size_t, const char *, void *),
645 * get difference between two versions of an image
647 * This will return the differences between two versions of an image
648 * via a callback, which gets the offset and length and a flag
649 * indicating whether the extent exists (1), or is known/defined to
650 * be zeros (a hole, 0). If the source snapshot name is NULL, we
651 * interpret that as the beginning of time and return all allocated
652 * regions of the image. The end version is whatever is currently
653 * selected for the image handle (either a snapshot or the writeable
656 * @param fromsnapname start snapshot name, or NULL
657 * @param ofs start offset
658 * @param len len in bytes of region to report on
659 * @param include_parent 1 if full history diff should include parent
660 * @param whole_object 1 if diff extents should cover whole object
661 * @param cb callback to call for each allocated region
662 * @param arg argument to pass to the callback
663 * @returns 0 on success, or negative error code on error
665 CEPH_RBD_API
int rbd_diff_iterate(rbd_image_t image
,
666 const char *fromsnapname
,
667 uint64_t ofs
, uint64_t len
,
668 int (*cb
)(uint64_t, size_t, int, void *),
670 CEPH_RBD_API
int rbd_diff_iterate2(rbd_image_t image
,
671 const char *fromsnapname
,
672 uint64_t ofs
, uint64_t len
,
673 uint8_t include_parent
, uint8_t whole_object
,
674 int (*cb
)(uint64_t, size_t, int, void *),
676 CEPH_RBD_API ssize_t
rbd_write(rbd_image_t image
, uint64_t ofs
, size_t len
,
679 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
681 CEPH_RBD_API ssize_t
rbd_write2(rbd_image_t image
, uint64_t ofs
, size_t len
,
682 const char *buf
, int op_flags
);
683 CEPH_RBD_API
int rbd_discard(rbd_image_t image
, uint64_t ofs
, uint64_t len
);
684 CEPH_RBD_API ssize_t
rbd_writesame(rbd_image_t image
, uint64_t ofs
, size_t len
,
685 const char *buf
, size_t data_len
, int op_flags
);
686 CEPH_RBD_API ssize_t
rbd_compare_and_write(rbd_image_t image
, uint64_t ofs
,
687 size_t len
, const char *cmp_buf
,
688 const char *buf
, uint64_t *mismatch_off
,
691 CEPH_RBD_API
int rbd_aio_write(rbd_image_t image
, uint64_t off
, size_t len
,
692 const char *buf
, rbd_completion_t c
);
695 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
697 CEPH_RBD_API
int rbd_aio_write2(rbd_image_t image
, uint64_t off
, size_t len
,
698 const char *buf
, rbd_completion_t c
,
700 CEPH_RBD_API
int rbd_aio_writev(rbd_image_t image
, const struct iovec
*iov
,
701 int iovcnt
, uint64_t off
, rbd_completion_t c
);
702 CEPH_RBD_API
int rbd_aio_read(rbd_image_t image
, uint64_t off
, size_t len
,
703 char *buf
, rbd_completion_t c
);
705 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
707 CEPH_RBD_API
int rbd_aio_read2(rbd_image_t image
, uint64_t off
, size_t len
,
708 char *buf
, rbd_completion_t c
, int op_flags
);
709 CEPH_RBD_API
int rbd_aio_readv(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_discard(rbd_image_t image
, uint64_t off
, uint64_t len
,
713 CEPH_RBD_API
int rbd_aio_writesame(rbd_image_t image
, uint64_t off
, size_t len
,
714 const char *buf
, size_t data_len
,
715 rbd_completion_t c
, int op_flags
);
716 CEPH_RBD_API ssize_t
rbd_aio_compare_and_write(rbd_image_t image
,
717 uint64_t off
, size_t len
,
718 const char *cmp_buf
, const char *buf
,
719 rbd_completion_t c
, uint64_t *mismatch_off
,
722 CEPH_RBD_API
int rbd_aio_create_completion(void *cb_arg
,
723 rbd_callback_t complete_cb
,
724 rbd_completion_t
*c
);
725 CEPH_RBD_API
int rbd_aio_is_complete(rbd_completion_t c
);
726 CEPH_RBD_API
int rbd_aio_wait_for_complete(rbd_completion_t c
);
727 CEPH_RBD_API ssize_t
rbd_aio_get_return_value(rbd_completion_t c
);
728 CEPH_RBD_API
void *rbd_aio_get_arg(rbd_completion_t c
);
729 CEPH_RBD_API
void rbd_aio_release(rbd_completion_t c
);
730 CEPH_RBD_API
int rbd_flush(rbd_image_t image
);
732 * Start a flush if caching is enabled. Get a callback when
733 * the currently pending writes are on disk.
735 * @param image the image to flush writes to
736 * @param c what to call when flushing is complete
737 * @returns 0 on success, negative error code on failure
739 CEPH_RBD_API
int rbd_aio_flush(rbd_image_t image
, rbd_completion_t c
);
742 * Drop any cached data for an image
744 * @param image the image to invalidate cached data for
745 * @returns 0 on success, negative error code on failure
747 CEPH_RBD_API
int rbd_invalidate_cache(rbd_image_t image
);
749 CEPH_RBD_API
int rbd_poll_io_events(rbd_image_t image
, rbd_completion_t
*comps
, int numcomp
);
751 CEPH_RBD_API
int rbd_metadata_get(rbd_image_t image
, const char *key
, char *value
, size_t *val_len
);
752 CEPH_RBD_API
int rbd_metadata_set(rbd_image_t image
, const char *key
, const char *value
);
753 CEPH_RBD_API
int rbd_metadata_remove(rbd_image_t image
, const char *key
);
755 * List all metadatas associated with this image.
757 * This iterates over all metadatas, key_len and val_len are filled in
758 * with the number of bytes put into the keys and values buffers.
760 * If the provided buffers are too short, the required lengths are
761 * still filled in, but the data is not and -ERANGE is returned.
762 * Otherwise, the buffers are filled with the keys and values
763 * of the image, with a '\0' after each.
765 * @param image which image (and implicitly snapshot) to list clones of
766 * @param start_after which name to begin listing after
767 * (use the empty string to start at the beginning)
768 * @param max the maximum number of names to lis(if 0 means no limit)
769 * @param keys buffer in which to store pool names
770 * @param keys_len number of bytes in pools buffer
771 * @param values buffer in which to store image names
772 * @param vals_len number of bytes in images buffer
773 * @returns number of children on success, negative error code on failure
774 * @returns -ERANGE if either buffer is too short
776 CEPH_RBD_API
int rbd_metadata_list(rbd_image_t image
, const char *start
, uint64_t max
,
777 char *keys
, size_t *key_len
, char *values
, size_t *vals_len
);
779 // RBD image mirroring support functions
780 CEPH_RBD_API
int rbd_mirror_image_enable(rbd_image_t image
);
781 CEPH_RBD_API
int rbd_mirror_image_disable(rbd_image_t image
, bool force
);
782 CEPH_RBD_API
int rbd_mirror_image_promote(rbd_image_t image
, bool force
);
783 CEPH_RBD_API
int rbd_mirror_image_demote(rbd_image_t image
);
784 CEPH_RBD_API
int rbd_mirror_image_resync(rbd_image_t image
);
785 CEPH_RBD_API
int rbd_mirror_image_get_info(rbd_image_t image
,
786 rbd_mirror_image_info_t
*mirror_image_info
,
788 CEPH_RBD_API
int rbd_mirror_image_get_status(rbd_image_t image
,
789 rbd_mirror_image_status_t
*mirror_image_status
,
791 CEPH_RBD_API
int rbd_aio_mirror_image_promote(rbd_image_t image
, bool force
,
793 CEPH_RBD_API
int rbd_aio_mirror_image_demote(rbd_image_t image
,
795 CEPH_RBD_API
int rbd_aio_mirror_image_get_info(rbd_image_t image
,
796 rbd_mirror_image_info_t
*mirror_image_info
,
799 CEPH_RBD_API
int rbd_aio_mirror_image_get_status(rbd_image_t image
,
800 rbd_mirror_image_status_t
*mirror_image_status
,
805 * Register an image metadata change watcher.
807 * @param image the image to watch
808 * @param handle where to store the internal id assigned to this watch
809 * @param watch_cb what to do when a notify is received on this image
810 * @param arg opaque value to pass to the callback
811 * @returns 0 on success, negative error code on failure
813 CEPH_RBD_API
int rbd_update_watch(rbd_image_t image
, uint64_t *handle
,
814 rbd_update_callback_t watch_cb
, void *arg
);
817 * Unregister an image watcher.
819 * @param image the image to unwatch
820 * @param handle which watch to unregister
821 * @returns 0 on success, negative error code on failure
823 CEPH_RBD_API
int rbd_update_unwatch(rbd_image_t image
, uint64_t handle
);