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 15
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
50 #define LIBRBD_SUPPORTS_WRITE_ZEROES 1
53 #define CEPH_RBD_API __attribute__ ((visibility ("default")))
54 #define CEPH_RBD_DEPRECATED __attribute__((deprecated))
55 #pragma GCC diagnostic push
56 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
59 #define CEPH_RBD_DEPRECATED
62 #define RBD_FLAG_OBJECT_MAP_INVALID (1<<0)
63 #define RBD_FLAG_FAST_DIFF_INVALID (1<<1)
65 #define RBD_MIRROR_IMAGE_STATUS_LOCAL_MIRROR_UUID ""
67 typedef void *rbd_image_t
;
68 typedef void *rbd_image_options_t
;
69 typedef void *rbd_pool_stats_t
;
71 typedef void *rbd_completion_t
;
72 typedef void (*rbd_callback_t
)(rbd_completion_t cb
, void *arg
);
74 typedef int (*librbd_progress_fn_t
)(uint64_t offset
, uint64_t total
, void *ptr
);
76 typedef void (*rbd_update_callback_t
)(void *arg
);
79 RBD_SNAP_NAMESPACE_TYPE_USER
= 0,
80 RBD_SNAP_NAMESPACE_TYPE_GROUP
= 1,
81 RBD_SNAP_NAMESPACE_TYPE_TRASH
= 2,
82 RBD_SNAP_NAMESPACE_TYPE_MIRROR
= 3,
83 } rbd_snap_namespace_type_t
;
97 } rbd_linked_image_spec_t
;
101 rbd_snap_namespace_type_t namespace_type
;
112 const char *pool_name
;
113 const char *image_name
;
114 const char *image_id
;
118 #define RBD_MAX_IMAGE_NAME_SIZE 96
119 #define RBD_MAX_BLOCK_NAME_SIZE 24
121 #define RBD_SNAP_REMOVE_UNPROTECT 1 << 0
122 #define RBD_SNAP_REMOVE_FLATTEN 1 << 1
123 #define RBD_SNAP_REMOVE_FORCE (RBD_SNAP_REMOVE_UNPROTECT | RBD_SNAP_REMOVE_FLATTEN)
126 * These types used to in set_image_notification to indicate the type of event
131 EVENT_TYPE_EVENTFD
= 2
139 char block_name_prefix
[RBD_MAX_BLOCK_NAME_SIZE
]; /* deprecated */
140 int64_t parent_pool
; /* deprecated */
141 char parent_name
[RBD_MAX_IMAGE_NAME_SIZE
]; /* deprecated */
145 RBD_MIRROR_MODE_DISABLED
, /* mirroring is disabled */
146 RBD_MIRROR_MODE_IMAGE
, /* mirroring enabled on a per-image basis */
147 RBD_MIRROR_MODE_POOL
/* mirroring enabled on all journaled images */
151 RBD_MIRROR_PEER_DIRECTION_RX
= 0,
152 RBD_MIRROR_PEER_DIRECTION_TX
= 1,
153 RBD_MIRROR_PEER_DIRECTION_RX_TX
= 2
154 } rbd_mirror_peer_direction_t
;
160 } rbd_mirror_peer_t CEPH_RBD_DEPRECATED
;
164 rbd_mirror_peer_direction_t direction
;
169 } rbd_mirror_peer_site_t
;
171 #define RBD_MIRROR_PEER_ATTRIBUTE_NAME_MON_HOST "mon_host"
172 #define RBD_MIRROR_PEER_ATTRIBUTE_NAME_KEY "key"
175 RBD_MIRROR_IMAGE_MODE_JOURNAL
= 0,
176 RBD_MIRROR_IMAGE_MODE_SNAPSHOT
= 1,
177 } rbd_mirror_image_mode_t
;
180 RBD_MIRROR_IMAGE_DISABLING
= 0,
181 RBD_MIRROR_IMAGE_ENABLED
= 1,
182 RBD_MIRROR_IMAGE_DISABLED
= 2
183 } rbd_mirror_image_state_t
;
187 rbd_mirror_image_state_t state
;
189 } rbd_mirror_image_info_t
;
192 MIRROR_IMAGE_STATUS_STATE_UNKNOWN
= 0,
193 MIRROR_IMAGE_STATUS_STATE_ERROR
= 1,
194 MIRROR_IMAGE_STATUS_STATE_SYNCING
= 2,
195 MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY
= 3,
196 MIRROR_IMAGE_STATUS_STATE_REPLAYING
= 4,
197 MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY
= 5,
198 MIRROR_IMAGE_STATUS_STATE_STOPPED
= 6,
199 } rbd_mirror_image_status_state_t
;
203 rbd_mirror_image_info_t info
;
204 rbd_mirror_image_status_state_t state
;
208 } rbd_mirror_image_status_t CEPH_RBD_DEPRECATED
;
212 rbd_mirror_image_status_state_t state
;
216 } rbd_mirror_image_site_status_t
;
220 rbd_mirror_image_info_t info
;
221 uint32_t site_statuses_count
;
222 rbd_mirror_image_site_status_t
*site_statuses
;
223 } rbd_mirror_image_global_status_t
;
226 RBD_GROUP_IMAGE_STATE_ATTACHED
,
227 RBD_GROUP_IMAGE_STATE_INCOMPLETE
228 } rbd_group_image_state_t
;
233 rbd_group_image_state_t state
;
234 } rbd_group_image_info_t
;
242 RBD_GROUP_SNAP_STATE_INCOMPLETE
,
243 RBD_GROUP_SNAP_STATE_COMPLETE
244 } rbd_group_snap_state_t
;
248 rbd_group_snap_state_t state
;
249 } rbd_group_snap_info_t
;
254 char *group_snap_name
;
255 } rbd_snap_group_namespace_t
;
258 RBD_SNAP_MIRROR_STATE_PRIMARY
,
259 RBD_SNAP_MIRROR_STATE_PRIMARY_DEMOTED
,
260 RBD_SNAP_MIRROR_STATE_NON_PRIMARY
,
261 RBD_SNAP_MIRROR_STATE_NON_PRIMARY_DEMOTED
262 } rbd_snap_mirror_state_t
;
265 rbd_snap_mirror_state_t state
;
266 size_t mirror_peer_uuids_count
;
267 char *mirror_peer_uuids
;
269 char *primary_mirror_uuid
;
270 uint64_t primary_snap_id
;
271 uint64_t last_copied_object_number
;
272 } rbd_snap_mirror_namespace_t
;
275 RBD_LOCK_MODE_EXCLUSIVE
= 0,
276 RBD_LOCK_MODE_SHARED
= 1,
279 CEPH_RBD_API
void rbd_version(int *major
, int *minor
, int *extra
);
283 RBD_IMAGE_OPTION_FORMAT
= 0,
284 RBD_IMAGE_OPTION_FEATURES
= 1,
285 RBD_IMAGE_OPTION_ORDER
= 2,
286 RBD_IMAGE_OPTION_STRIPE_UNIT
= 3,
287 RBD_IMAGE_OPTION_STRIPE_COUNT
= 4,
288 RBD_IMAGE_OPTION_JOURNAL_ORDER
= 5,
289 RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH
= 6,
290 RBD_IMAGE_OPTION_JOURNAL_POOL
= 7,
291 RBD_IMAGE_OPTION_FEATURES_SET
= 8,
292 RBD_IMAGE_OPTION_FEATURES_CLEAR
= 9,
293 RBD_IMAGE_OPTION_DATA_POOL
= 10,
294 RBD_IMAGE_OPTION_FLATTEN
= 11,
295 RBD_IMAGE_OPTION_CLONE_FORMAT
= 12,
296 RBD_IMAGE_OPTION_MIRROR_IMAGE_MODE
= 13,
300 RBD_TRASH_IMAGE_SOURCE_USER
= 0,
301 RBD_TRASH_IMAGE_SOURCE_MIRRORING
= 1,
302 RBD_TRASH_IMAGE_SOURCE_MIGRATION
= 2,
303 RBD_TRASH_IMAGE_SOURCE_REMOVING
= 3,
304 RBD_TRASH_IMAGE_SOURCE_USER_PARENT
= 4,
305 } rbd_trash_image_source_t
;
310 rbd_trash_image_source_t source
;
311 time_t deletion_time
;
312 time_t deferment_end_time
;
313 } rbd_trash_image_info_t
;
319 } rbd_image_watcher_t
;
322 RBD_IMAGE_MIGRATION_STATE_UNKNOWN
= -1,
323 RBD_IMAGE_MIGRATION_STATE_ERROR
= 0,
324 RBD_IMAGE_MIGRATION_STATE_PREPARING
= 1,
325 RBD_IMAGE_MIGRATION_STATE_PREPARED
= 2,
326 RBD_IMAGE_MIGRATION_STATE_EXECUTING
= 3,
327 RBD_IMAGE_MIGRATION_STATE_EXECUTED
= 4,
328 RBD_IMAGE_MIGRATION_STATE_ABORTING
= 5,
329 } rbd_image_migration_state_t
;
332 int64_t source_pool_id
;
333 char *source_pool_namespace
;
334 char *source_image_name
;
335 char *source_image_id
;
336 int64_t dest_pool_id
;
337 char *dest_pool_namespace
;
338 char *dest_image_name
;
340 rbd_image_migration_state_t state
;
341 char *state_description
;
342 } rbd_image_migration_status_t
;
345 RBD_CONFIG_SOURCE_CONFIG
= 0,
346 RBD_CONFIG_SOURCE_POOL
= 1,
347 RBD_CONFIG_SOURCE_IMAGE
= 2,
348 } rbd_config_source_t
;
353 rbd_config_source_t source
;
354 } rbd_config_option_t
;
357 RBD_POOL_STAT_OPTION_IMAGES
,
358 RBD_POOL_STAT_OPTION_IMAGE_PROVISIONED_BYTES
,
359 RBD_POOL_STAT_OPTION_IMAGE_MAX_PROVISIONED_BYTES
,
360 RBD_POOL_STAT_OPTION_IMAGE_SNAPSHOTS
,
361 RBD_POOL_STAT_OPTION_TRASH_IMAGES
,
362 RBD_POOL_STAT_OPTION_TRASH_PROVISIONED_BYTES
,
363 RBD_POOL_STAT_OPTION_TRASH_MAX_PROVISIONED_BYTES
,
364 RBD_POOL_STAT_OPTION_TRASH_SNAPSHOTS
365 } rbd_pool_stat_option_t
;
367 CEPH_RBD_API
void rbd_image_options_create(rbd_image_options_t
* opts
);
368 CEPH_RBD_API
void rbd_image_options_destroy(rbd_image_options_t opts
);
369 CEPH_RBD_API
int rbd_image_options_set_string(rbd_image_options_t opts
,
370 int optname
, const char* optval
);
371 CEPH_RBD_API
int rbd_image_options_set_uint64(rbd_image_options_t opts
,
372 int optname
, uint64_t optval
);
373 CEPH_RBD_API
int rbd_image_options_get_string(rbd_image_options_t opts
,
374 int optname
, char* optval
,
376 CEPH_RBD_API
int rbd_image_options_get_uint64(rbd_image_options_t opts
,
377 int optname
, uint64_t* optval
);
378 CEPH_RBD_API
int rbd_image_options_is_set(rbd_image_options_t opts
,
379 int optname
, bool* is_set
);
380 CEPH_RBD_API
int rbd_image_options_unset(rbd_image_options_t opts
, int optname
);
381 CEPH_RBD_API
void rbd_image_options_clear(rbd_image_options_t opts
);
382 CEPH_RBD_API
int rbd_image_options_is_empty(rbd_image_options_t opts
);
385 CEPH_RBD_API
void rbd_image_spec_cleanup(rbd_image_spec_t
*image
);
386 CEPH_RBD_API
void rbd_image_spec_list_cleanup(rbd_image_spec_t
*images
,
388 CEPH_RBD_API
void rbd_linked_image_spec_cleanup(rbd_linked_image_spec_t
*image
);
389 CEPH_RBD_API
void rbd_linked_image_spec_list_cleanup(
390 rbd_linked_image_spec_t
*images
, size_t num_images
);
391 CEPH_RBD_API
void rbd_snap_spec_cleanup(rbd_snap_spec_t
*snap
);
394 CEPH_RBD_API
int rbd_list(rados_ioctx_t io
, char *names
, size_t *size
)
396 CEPH_RBD_API
int rbd_list2(rados_ioctx_t io
, rbd_image_spec_t
* images
,
399 CEPH_RBD_API
int rbd_create(rados_ioctx_t io
, const char *name
, uint64_t size
,
401 CEPH_RBD_API
int rbd_create2(rados_ioctx_t io
, const char *name
, uint64_t size
,
402 uint64_t features
, int *order
);
404 * create new rbd image
406 * The stripe_unit must be a factor of the object size (1 << order).
407 * The stripe_count can be one (no intra-object striping) or greater
408 * than one. The RBD_FEATURE_STRIPINGV2 must be specified if the
409 * stripe_unit != the object size and the stripe_count is != 1.
412 * @param name image name
413 * @param size image size in bytes
414 * @param features initial feature bits
415 * @param order object/block size, as a power of two (object size == 1 << order)
416 * @param stripe_unit stripe unit size, in bytes.
417 * @param stripe_count number of objects to stripe over before looping
418 * @return 0 on success, or negative error code
420 CEPH_RBD_API
int rbd_create3(rados_ioctx_t io
, const char *name
, uint64_t size
,
421 uint64_t features
, int *order
,
422 uint64_t stripe_unit
, uint64_t stripe_count
);
423 CEPH_RBD_API
int rbd_create4(rados_ioctx_t io
, const char *name
, uint64_t size
,
424 rbd_image_options_t opts
);
425 CEPH_RBD_API
int rbd_clone(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 CEPH_RBD_API
int rbd_clone2(rados_ioctx_t p_ioctx
, const char *p_name
,
429 const char *p_snapname
, rados_ioctx_t c_ioctx
,
430 const char *c_name
, uint64_t features
, int *c_order
,
431 uint64_t stripe_unit
, int stripe_count
);
432 CEPH_RBD_API
int rbd_clone3(rados_ioctx_t p_ioctx
, const char *p_name
,
433 const char *p_snapname
, rados_ioctx_t c_ioctx
,
434 const char *c_name
, rbd_image_options_t c_opts
);
435 CEPH_RBD_API
int rbd_remove(rados_ioctx_t io
, const char *name
);
436 CEPH_RBD_API
int rbd_remove_with_progress(rados_ioctx_t io
, const char *name
,
437 librbd_progress_fn_t cb
,
439 CEPH_RBD_API
int rbd_rename(rados_ioctx_t src_io_ctx
, const char *srcname
,
440 const char *destname
);
442 CEPH_RBD_API
int rbd_trash_move(rados_ioctx_t io
, const char *name
,
444 CEPH_RBD_API
int rbd_trash_get(rados_ioctx_t io
, const char *id
,
445 rbd_trash_image_info_t
*info
);
446 CEPH_RBD_API
void rbd_trash_get_cleanup(rbd_trash_image_info_t
*info
);
447 CEPH_RBD_API
int rbd_trash_list(rados_ioctx_t io
,
448 rbd_trash_image_info_t
*trash_entries
,
449 size_t *num_entries
);
450 CEPH_RBD_API
void rbd_trash_list_cleanup(rbd_trash_image_info_t
*trash_entries
,
452 CEPH_RBD_API
int rbd_trash_purge(rados_ioctx_t io
, time_t expire_ts
, float threshold
);
453 CEPH_RBD_API
int rbd_trash_purge_with_progress(rados_ioctx_t io
, time_t expire_ts
,
454 float threshold
, librbd_progress_fn_t cb
,
456 CEPH_RBD_API
int rbd_trash_remove(rados_ioctx_t io
, const char *id
, bool force
);
457 CEPH_RBD_API
int rbd_trash_remove_with_progress(rados_ioctx_t io
,
460 librbd_progress_fn_t cb
,
462 CEPH_RBD_API
int rbd_trash_restore(rados_ioctx_t io
, const char *id
,
466 CEPH_RBD_API
int rbd_migration_prepare(rados_ioctx_t ioctx
,
467 const char *image_name
,
468 rados_ioctx_t dest_ioctx
,
469 const char *dest_image_name
,
470 rbd_image_options_t opts
);
471 CEPH_RBD_API
int rbd_migration_execute(rados_ioctx_t ioctx
,
472 const char *image_name
);
473 CEPH_RBD_API
int rbd_migration_execute_with_progress(rados_ioctx_t ioctx
,
474 const char *image_name
,
475 librbd_progress_fn_t cb
,
477 CEPH_RBD_API
int rbd_migration_abort(rados_ioctx_t ioctx
,
478 const char *image_name
);
479 CEPH_RBD_API
int rbd_migration_abort_with_progress(rados_ioctx_t ioctx
,
480 const char *image_name
,
481 librbd_progress_fn_t cb
,
483 CEPH_RBD_API
int rbd_migration_commit(rados_ioctx_t ioctx
,
484 const char *image_name
);
485 CEPH_RBD_API
int rbd_migration_commit_with_progress(rados_ioctx_t ioctx
,
486 const char *image_name
,
487 librbd_progress_fn_t cb
,
489 CEPH_RBD_API
int rbd_migration_status(rados_ioctx_t ioctx
,
490 const char *image_name
,
491 rbd_image_migration_status_t
*status
,
493 CEPH_RBD_API
void rbd_migration_status_cleanup(
494 rbd_image_migration_status_t
*status
);
497 CEPH_RBD_API
int rbd_mirror_site_name_get(rados_t cluster
,
498 char *name
, size_t *max_len
);
499 CEPH_RBD_API
int rbd_mirror_site_name_set(rados_t cluster
,
502 CEPH_RBD_API
int rbd_mirror_mode_get(rados_ioctx_t io_ctx
,
503 rbd_mirror_mode_t
*mirror_mode
);
504 CEPH_RBD_API
int rbd_mirror_mode_set(rados_ioctx_t io_ctx
,
505 rbd_mirror_mode_t mirror_mode
);
507 CEPH_RBD_API
int rbd_mirror_uuid_get(rados_ioctx_t io_ctx
,
508 char *uuid
, size_t *max_len
);
510 CEPH_RBD_API
int rbd_mirror_peer_bootstrap_create(
511 rados_ioctx_t io_ctx
, char *token
, size_t *max_len
);
512 CEPH_RBD_API
int rbd_mirror_peer_bootstrap_import(
513 rados_ioctx_t io_ctx
, rbd_mirror_peer_direction_t direction
,
516 CEPH_RBD_API
int rbd_mirror_peer_site_add(
517 rados_ioctx_t io_ctx
, char *uuid
, size_t uuid_max_length
,
518 rbd_mirror_peer_direction_t direction
, const char *site_name
,
519 const char *client_name
);
520 CEPH_RBD_API
int rbd_mirror_peer_site_set_name(
521 rados_ioctx_t io_ctx
, const char *uuid
, const char *site_name
);
522 CEPH_RBD_API
int rbd_mirror_peer_site_set_client_name(
523 rados_ioctx_t io_ctx
, const char *uuid
, const char *client_name
);
524 CEPH_RBD_API
int rbd_mirror_peer_site_set_direction(
525 rados_ioctx_t io_ctx
, const char *uuid
,
526 rbd_mirror_peer_direction_t direction
);
527 CEPH_RBD_API
int rbd_mirror_peer_site_remove(
528 rados_ioctx_t io_ctx
, const char *uuid
);
529 CEPH_RBD_API
int rbd_mirror_peer_site_list(
530 rados_ioctx_t io_ctx
, rbd_mirror_peer_site_t
*peers
, int *max_peers
);
531 CEPH_RBD_API
void rbd_mirror_peer_site_list_cleanup(
532 rbd_mirror_peer_site_t
*peers
, int max_peers
);
533 CEPH_RBD_API
int rbd_mirror_peer_site_get_attributes(
534 rados_ioctx_t p
, const char *uuid
, char *keys
, size_t *max_key_len
,
535 char *values
, size_t *max_value_len
, size_t *key_value_count
);
536 CEPH_RBD_API
int rbd_mirror_peer_site_set_attributes(
537 rados_ioctx_t p
, const char *uuid
, const char *keys
, const char *values
,
538 size_t key_value_count
);
540 CEPH_RBD_API
int rbd_mirror_image_global_status_list(
541 rados_ioctx_t io_ctx
, const char *start_id
, size_t max
, char **image_ids
,
542 rbd_mirror_image_global_status_t
*images
, size_t *len
);
543 CEPH_RBD_API
void rbd_mirror_image_global_status_list_cleanup(
544 char **image_ids
, rbd_mirror_image_global_status_t
*images
, size_t len
);
546 /* rbd_mirror_peer_ commands are deprecated to rbd_mirror_peer_site_
548 CEPH_RBD_API
int rbd_mirror_peer_add(
549 rados_ioctx_t io_ctx
, char *uuid
, size_t uuid_max_length
,
550 const char *cluster_name
, const char *client_name
)
552 CEPH_RBD_API
int rbd_mirror_peer_remove(
553 rados_ioctx_t io_ctx
, const char *uuid
)
555 CEPH_RBD_API
int rbd_mirror_peer_list(
556 rados_ioctx_t io_ctx
, rbd_mirror_peer_t
*peers
, int *max_peers
)
558 CEPH_RBD_API
void rbd_mirror_peer_list_cleanup(
559 rbd_mirror_peer_t
*peers
, int max_peers
)
561 CEPH_RBD_API
int rbd_mirror_peer_set_client(
562 rados_ioctx_t io_ctx
, const char *uuid
, const char *client_name
)
564 CEPH_RBD_API
int rbd_mirror_peer_set_cluster(
565 rados_ioctx_t io_ctx
, const char *uuid
, const char *cluster_name
)
567 CEPH_RBD_API
int rbd_mirror_peer_get_attributes(
568 rados_ioctx_t p
, const char *uuid
, char *keys
, size_t *max_key_len
,
569 char *values
, size_t *max_value_len
, size_t *key_value_count
)
571 CEPH_RBD_API
int rbd_mirror_peer_set_attributes(
572 rados_ioctx_t p
, const char *uuid
, const char *keys
, const char *values
,
573 size_t key_value_count
)
576 /* rbd_mirror_image_status_list_ commands are deprecard to
577 * rbd_mirror_image_global_status_list_ commands */
579 CEPH_RBD_API
int rbd_mirror_image_status_list(
580 rados_ioctx_t io_ctx
, const char *start_id
, size_t max
, char **image_ids
,
581 rbd_mirror_image_status_t
*images
, size_t *len
)
583 CEPH_RBD_API
void rbd_mirror_image_status_list_cleanup(
584 char **image_ids
, rbd_mirror_image_status_t
*images
, size_t len
)
587 CEPH_RBD_API
int rbd_mirror_image_status_summary(
588 rados_ioctx_t io_ctx
, rbd_mirror_image_status_state_t
*states
, int *counts
,
591 CEPH_RBD_API
int rbd_mirror_image_instance_id_list(rados_ioctx_t io_ctx
,
592 const char *start_id
,
593 size_t max
, char **image_ids
,
596 CEPH_RBD_API
void rbd_mirror_image_instance_id_list_cleanup(char **image_ids
,
599 CEPH_RBD_API
int rbd_mirror_image_info_list(
600 rados_ioctx_t io_ctx
, rbd_mirror_image_mode_t
*mode_filter
,
601 const char *start_id
, size_t max
, char **image_ids
,
602 rbd_mirror_image_mode_t
*mode_entries
,
603 rbd_mirror_image_info_t
*info_entries
, size_t *num_entries
);
604 CEPH_RBD_API
void rbd_mirror_image_info_list_cleanup(
605 char **image_ids
, rbd_mirror_image_info_t
*info_entries
,
609 CEPH_RBD_API
int rbd_pool_metadata_get(rados_ioctx_t io_ctx
, const char *key
,
610 char *value
, size_t *val_len
);
611 CEPH_RBD_API
int rbd_pool_metadata_set(rados_ioctx_t io_ctx
, const char *key
,
613 CEPH_RBD_API
int rbd_pool_metadata_remove(rados_ioctx_t io_ctx
,
615 CEPH_RBD_API
int rbd_pool_metadata_list(rados_ioctx_t io_ctx
, const char *start
,
616 uint64_t max
, char *keys
,
617 size_t *key_len
, char *values
,
620 CEPH_RBD_API
int rbd_config_pool_list(rados_ioctx_t io_ctx
,
621 rbd_config_option_t
*options
,
623 CEPH_RBD_API
void rbd_config_pool_list_cleanup(rbd_config_option_t
*options
,
626 CEPH_RBD_API
int rbd_open(rados_ioctx_t io
, const char *name
,
627 rbd_image_t
*image
, const char *snap_name
);
628 CEPH_RBD_API
int rbd_open_by_id(rados_ioctx_t io
, const char *id
,
629 rbd_image_t
*image
, const char *snap_name
);
631 CEPH_RBD_API
int rbd_aio_open(rados_ioctx_t io
, const char *name
,
632 rbd_image_t
*image
, const char *snap_name
,
634 CEPH_RBD_API
int rbd_aio_open_by_id(rados_ioctx_t io
, const char *id
,
635 rbd_image_t
*image
, const char *snap_name
,
639 * Open an image in read-only mode.
641 * This is intended for use by clients that cannot write to a block
642 * device due to cephx restrictions. There will be no watch
643 * established on the header object, since a watch is a write. This
644 * means the metadata reported about this image (parents, snapshots,
645 * size, etc.) may become stale. This should not be used for
646 * long-running operations, unless you can be sure that one of these
647 * properties changing is safe.
649 * Attempting to write to a read-only image will return -EROFS.
651 * @param io ioctx to determine the pool the image is in
652 * @param name image name
653 * @param image where to store newly opened image handle
654 * @param snap_name name of snapshot to open at, or NULL for no snapshot
655 * @returns 0 on success, negative error code on failure
657 CEPH_RBD_API
int rbd_open_read_only(rados_ioctx_t io
, const char *name
,
658 rbd_image_t
*image
, const char *snap_name
);
659 CEPH_RBD_API
int rbd_open_by_id_read_only(rados_ioctx_t io
, const char *id
,
660 rbd_image_t
*image
, const char *snap_name
);
661 CEPH_RBD_API
int rbd_aio_open_read_only(rados_ioctx_t io
, const char *name
,
662 rbd_image_t
*image
, const char *snap_name
,
664 CEPH_RBD_API
int rbd_aio_open_by_id_read_only(rados_ioctx_t io
, const char *id
,
665 rbd_image_t
*image
, const char *snap_name
,
667 CEPH_RBD_API
int rbd_features_to_string(uint64_t features
, char *str_features
,
669 CEPH_RBD_API
int rbd_features_from_string(const char *str_features
, uint64_t *features
);
670 CEPH_RBD_API
int rbd_close(rbd_image_t image
);
671 CEPH_RBD_API
int rbd_aio_close(rbd_image_t image
, rbd_completion_t c
);
672 CEPH_RBD_API
int rbd_resize(rbd_image_t image
, uint64_t size
);
673 CEPH_RBD_API
int rbd_resize2(rbd_image_t image
, uint64_t size
, bool allow_shrink
,
674 librbd_progress_fn_t cb
, void *cbdata
);
675 CEPH_RBD_API
int rbd_resize_with_progress(rbd_image_t image
, uint64_t size
,
676 librbd_progress_fn_t cb
, void *cbdata
);
677 CEPH_RBD_API
int rbd_stat(rbd_image_t image
, rbd_image_info_t
*info
,
679 CEPH_RBD_API
int rbd_get_old_format(rbd_image_t image
, uint8_t *old
);
680 CEPH_RBD_API
int rbd_get_size(rbd_image_t image
, uint64_t *size
);
681 CEPH_RBD_API
int rbd_get_features(rbd_image_t image
, uint64_t *features
);
682 CEPH_RBD_API
int rbd_update_features(rbd_image_t image
, uint64_t features
,
684 CEPH_RBD_API
int rbd_get_op_features(rbd_image_t image
, uint64_t *op_features
);
685 CEPH_RBD_API
int rbd_get_stripe_unit(rbd_image_t image
, uint64_t *stripe_unit
);
686 CEPH_RBD_API
int rbd_get_stripe_count(rbd_image_t image
,
687 uint64_t *stripe_count
);
689 CEPH_RBD_API
int rbd_get_create_timestamp(rbd_image_t image
,
690 struct timespec
*timestamp
);
691 CEPH_RBD_API
int rbd_get_access_timestamp(rbd_image_t image
,
692 struct timespec
*timestamp
);
693 CEPH_RBD_API
int rbd_get_modify_timestamp(rbd_image_t image
,
694 struct timespec
*timestamp
);
696 CEPH_RBD_API
int rbd_get_overlap(rbd_image_t image
, uint64_t *overlap
);
697 CEPH_RBD_API
int rbd_get_name(rbd_image_t image
, char *name
, size_t *name_len
);
698 CEPH_RBD_API
int rbd_get_id(rbd_image_t image
, char *id
, size_t id_len
);
699 CEPH_RBD_API
int rbd_get_block_name_prefix(rbd_image_t image
,
700 char *prefix
, size_t prefix_len
);
701 CEPH_RBD_API
int64_t rbd_get_data_pool_id(rbd_image_t image
);
703 CEPH_RBD_API
int rbd_get_parent_info(rbd_image_t image
,
704 char *parent_poolname
, size_t ppoolnamelen
,
705 char *parent_name
, size_t pnamelen
,
706 char *parent_snapname
,
709 CEPH_RBD_API
int rbd_get_parent_info2(rbd_image_t image
,
710 char *parent_poolname
,
712 char *parent_name
, size_t pnamelen
,
713 char *parent_id
, size_t pidlen
,
714 char *parent_snapname
,
717 CEPH_RBD_API
int rbd_get_parent(rbd_image_t image
,
718 rbd_linked_image_spec_t
*parent_image
,
719 rbd_snap_spec_t
*parent_snap
);
721 CEPH_RBD_API
int rbd_get_flags(rbd_image_t image
, uint64_t *flags
);
722 CEPH_RBD_API
int rbd_get_group(rbd_image_t image
, rbd_group_info_t
*group_info
,
723 size_t group_info_size
);
724 CEPH_RBD_API
int rbd_set_image_notification(rbd_image_t image
, int fd
, int type
);
726 /* exclusive lock feature */
727 CEPH_RBD_API
int rbd_is_exclusive_lock_owner(rbd_image_t image
, int *is_owner
);
728 CEPH_RBD_API
int rbd_lock_acquire(rbd_image_t image
, rbd_lock_mode_t lock_mode
);
729 CEPH_RBD_API
int rbd_lock_release(rbd_image_t image
);
730 CEPH_RBD_API
int rbd_lock_get_owners(rbd_image_t image
,
731 rbd_lock_mode_t
*lock_mode
,
733 size_t *max_lock_owners
);
734 CEPH_RBD_API
void rbd_lock_get_owners_cleanup(char **lock_owners
,
735 size_t lock_owner_count
);
736 CEPH_RBD_API
int rbd_lock_break(rbd_image_t image
, rbd_lock_mode_t lock_mode
,
737 const char *lock_owner
);
739 /* object map feature */
740 CEPH_RBD_API
int rbd_rebuild_object_map(rbd_image_t image
,
741 librbd_progress_fn_t cb
, void *cbdata
);
743 CEPH_RBD_API
int rbd_copy(rbd_image_t image
, rados_ioctx_t dest_io_ctx
,
744 const char *destname
);
745 CEPH_RBD_API
int rbd_copy2(rbd_image_t src
, rbd_image_t dest
);
746 CEPH_RBD_API
int rbd_copy3(rbd_image_t src
, rados_ioctx_t dest_io_ctx
,
747 const char *destname
, rbd_image_options_t dest_opts
);
748 CEPH_RBD_API
int rbd_copy4(rbd_image_t src
, rados_ioctx_t dest_io_ctx
,
749 const char *destname
, rbd_image_options_t dest_opts
,
751 CEPH_RBD_API
int rbd_copy_with_progress(rbd_image_t image
, rados_ioctx_t dest_p
,
752 const char *destname
,
753 librbd_progress_fn_t cb
, void *cbdata
);
754 CEPH_RBD_API
int rbd_copy_with_progress2(rbd_image_t src
, rbd_image_t dest
,
755 librbd_progress_fn_t cb
, void *cbdata
);
756 CEPH_RBD_API
int rbd_copy_with_progress3(rbd_image_t image
,
757 rados_ioctx_t dest_p
,
758 const char *destname
,
759 rbd_image_options_t dest_opts
,
760 librbd_progress_fn_t cb
, void *cbdata
);
761 CEPH_RBD_API
int rbd_copy_with_progress4(rbd_image_t image
,
762 rados_ioctx_t dest_p
,
763 const char *destname
,
764 rbd_image_options_t dest_opts
,
765 librbd_progress_fn_t cb
, void *cbdata
,
769 CEPH_RBD_API
int rbd_deep_copy(rbd_image_t src
, rados_ioctx_t dest_io_ctx
,
770 const char *destname
,
771 rbd_image_options_t dest_opts
);
772 CEPH_RBD_API
int rbd_deep_copy_with_progress(rbd_image_t image
,
773 rados_ioctx_t dest_io_ctx
,
774 const char *destname
,
775 rbd_image_options_t dest_opts
,
776 librbd_progress_fn_t cb
,
780 CEPH_RBD_API
int rbd_snap_list(rbd_image_t image
, rbd_snap_info_t
*snaps
,
782 CEPH_RBD_API
void rbd_snap_list_end(rbd_snap_info_t
*snaps
);
783 CEPH_RBD_API
int rbd_snap_exists(rbd_image_t image
, const char *snapname
, bool *exists
);
784 CEPH_RBD_API
int rbd_snap_create(rbd_image_t image
, const char *snapname
);
785 CEPH_RBD_API
int rbd_snap_remove(rbd_image_t image
, const char *snapname
);
786 CEPH_RBD_API
int rbd_snap_remove2(rbd_image_t image
, const char *snap_name
,
787 uint32_t flags
, librbd_progress_fn_t cb
,
789 CEPH_RBD_API
int rbd_snap_remove_by_id(rbd_image_t image
, uint64_t snap_id
);
790 CEPH_RBD_API
int rbd_snap_rollback(rbd_image_t image
, const char *snapname
);
791 CEPH_RBD_API
int rbd_snap_rollback_with_progress(rbd_image_t image
,
792 const char *snapname
,
793 librbd_progress_fn_t cb
,
795 CEPH_RBD_API
int rbd_snap_rename(rbd_image_t image
, const char *snapname
,
796 const char* dstsnapsname
);
798 * Prevent a snapshot from being deleted until it is unprotected.
800 * @param snap_name which snapshot to protect
801 * @returns 0 on success, negative error code on failure
802 * @returns -EBUSY if snap is already protected
804 CEPH_RBD_API
int rbd_snap_protect(rbd_image_t image
, const char *snap_name
);
806 * Allow a snaphshot to be deleted.
808 * @param snap_name which snapshot to unprotect
809 * @returns 0 on success, negative error code on failure
810 * @returns -EINVAL if snap is not protected
812 CEPH_RBD_API
int rbd_snap_unprotect(rbd_image_t image
, const char *snap_name
);
814 * Determine whether a snapshot is protected.
816 * @param snap_name which snapshot query
817 * @param is_protected where to store the result (0 or 1)
818 * @returns 0 on success, negative error code on failure
820 CEPH_RBD_API
int rbd_snap_is_protected(rbd_image_t image
, const char *snap_name
,
823 * Get the current snapshot limit for an image. If no limit is set,
824 * UINT64_MAX is returned.
826 * @param limit pointer where the limit will be stored on success
827 * @returns 0 on success, negative error code on failure
829 CEPH_RBD_API
int rbd_snap_get_limit(rbd_image_t image
, uint64_t *limit
);
832 * Set a limit for the number of snapshots that may be taken of an image.
834 * @param limit the maximum number of snapshots allowed in the future.
835 * @returns 0 on success, negative error code on failure
837 CEPH_RBD_API
int rbd_snap_set_limit(rbd_image_t image
, uint64_t limit
);
840 * Get the timestamp of a snapshot for an image.
842 * @param snap_id the snap id of a snapshot of input image.
843 * @param timestamp the timestamp of input snapshot.
844 * @returns 0 on success, negative error code on failure
846 CEPH_RBD_API
int rbd_snap_get_timestamp(rbd_image_t image
, uint64_t snap_id
, struct timespec
*timestamp
);
848 CEPH_RBD_API
int rbd_snap_set(rbd_image_t image
, const char *snapname
);
849 CEPH_RBD_API
int rbd_snap_set_by_id(rbd_image_t image
, uint64_t snap_id
);
850 CEPH_RBD_API
int rbd_snap_get_name(rbd_image_t image
, uint64_t snap_id
, char *snapname
, size_t *name_len
);
851 CEPH_RBD_API
int rbd_snap_get_id(rbd_image_t image
, const char *snapname
, uint64_t *snap_id
);
853 CEPH_RBD_API
int rbd_snap_get_namespace_type(rbd_image_t image
,
855 rbd_snap_namespace_type_t
*namespace_type
);
856 CEPH_RBD_API
int rbd_snap_get_group_namespace(rbd_image_t image
,
858 rbd_snap_group_namespace_t
*group_snap
,
859 size_t group_snap_size
);
860 CEPH_RBD_API
int rbd_snap_group_namespace_cleanup(rbd_snap_group_namespace_t
*group_snap
,
861 size_t group_snap_size
);
862 CEPH_RBD_API
int rbd_snap_get_trash_namespace(rbd_image_t image
,
866 CEPH_RBD_API
int rbd_snap_get_mirror_namespace(
867 rbd_image_t image
, uint64_t snap_id
,
868 rbd_snap_mirror_namespace_t
*mirror_snap
, size_t mirror_snap_size
);
869 CEPH_RBD_API
int rbd_snap_mirror_namespace_cleanup(
870 rbd_snap_mirror_namespace_t
*mirror_snap
, size_t mirror_snap_size
);
872 CEPH_RBD_API
int rbd_flatten(rbd_image_t image
);
874 CEPH_RBD_API
int rbd_flatten_with_progress(rbd_image_t image
,
875 librbd_progress_fn_t cb
,
878 CEPH_RBD_API
int rbd_sparsify(rbd_image_t image
, size_t sparse_size
);
880 CEPH_RBD_API
int rbd_sparsify_with_progress(rbd_image_t image
,
882 librbd_progress_fn_t cb
,
886 * List all images that are cloned from the image at the
887 * snapshot that is set via rbd_snap_set().
889 * This iterates over all pools, so it should be run by a user with
890 * read access to all of them. pools_len and images_len are filled in
891 * with the number of bytes put into the pools and images buffers.
893 * If the provided buffers are too short, the required lengths are
894 * still filled in, but the data is not and -ERANGE is returned.
895 * Otherwise, the buffers are filled with the pool and image names
896 * of the children, with a '\0' after each.
898 * @param image which image (and implicitly snapshot) to list clones of
899 * @param pools buffer in which to store pool names
900 * @param pools_len number of bytes in pools buffer
901 * @param images buffer in which to store image names
902 * @param images_len number of bytes in images buffer
903 * @returns number of children on success, negative error code on failure
904 * @returns -ERANGE if either buffer is too short
906 CEPH_RBD_API ssize_t
rbd_list_children(rbd_image_t image
, char *pools
,
907 size_t *pools_len
, char *images
,
910 CEPH_RBD_API
int rbd_list_children2(rbd_image_t image
,
911 rbd_child_info_t
*children
,
914 CEPH_RBD_API
void rbd_list_child_cleanup(rbd_child_info_t
*child
)
916 CEPH_RBD_API
void rbd_list_children_cleanup(rbd_child_info_t
*children
,
920 CEPH_RBD_API
int rbd_list_children3(rbd_image_t image
,
921 rbd_linked_image_spec_t
*images
,
924 CEPH_RBD_API
int rbd_list_descendants(rbd_image_t image
,
925 rbd_linked_image_spec_t
*images
,
929 * @defgroup librbd_h_locking Advisory Locking
931 * An rbd image may be locking exclusively, or shared, to facilitate
932 * e.g. live migration where the image may be open in two places at once.
933 * These locks are intended to guard against more than one client
934 * writing to an image without coordination. They don't need to
935 * be used for snapshots, since snapshots are read-only.
937 * Currently locks only guard against locks being acquired.
938 * They do not prevent anything else.
940 * A locker is identified by the internal rados client id of the
941 * holder and a user-defined cookie. This (client id, cookie) pair
942 * must be unique for each locker.
944 * A shared lock also has a user-defined tag associated with it. Each
945 * additional shared lock must specify the same tag or lock
946 * acquisition will fail. This can be used by e.g. groups of hosts
947 * using a clustered filesystem on top of an rbd image to make sure
948 * they're accessing the correct image.
953 * List clients that have locked the image and information about the lock.
955 * The number of bytes required in each buffer is put in the
956 * corresponding size out parameter. If any of the provided buffers
957 * are too short, -ERANGE is returned after these sizes are filled in.
959 * @param exclusive where to store whether the lock is exclusive (1) or shared (0)
960 * @param tag where to store the tag associated with the image
961 * @param tag_len number of bytes in tag buffer
962 * @param clients buffer in which locker clients are stored, separated by '\0'
963 * @param clients_len number of bytes in the clients buffer
964 * @param cookies buffer in which locker cookies are stored, separated by '\0'
965 * @param cookies_len number of bytes in the cookies buffer
966 * @param addrs buffer in which locker addresses are stored, separated by '\0'
967 * @param addrs_len number of bytes in the clients buffer
968 * @returns number of lockers on success, negative error code on failure
969 * @returns -ERANGE if any of the buffers are too short
971 CEPH_RBD_API ssize_t
rbd_list_lockers(rbd_image_t image
, int *exclusive
,
972 char *tag
, size_t *tag_len
,
973 char *clients
, size_t *clients_len
,
974 char *cookies
, size_t *cookies_len
,
975 char *addrs
, size_t *addrs_len
);
978 * Take an exclusive lock on the image.
980 * @param image the image to lock
981 * @param cookie user-defined identifier for this instance of the lock
982 * @returns 0 on success, negative error code on failure
983 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
984 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
986 CEPH_RBD_API
int rbd_lock_exclusive(rbd_image_t image
, const char *cookie
);
989 * Take a shared lock on the image.
991 * Other clients may also take a shared lock, as lock as they use the
994 * @param image the image to lock
995 * @param cookie user-defined identifier for this instance of the lock
996 * @param tag user-defined identifier for this shared use of the lock
997 * @returns 0 on success, negative error code on failure
998 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
999 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
1001 CEPH_RBD_API
int rbd_lock_shared(rbd_image_t image
, const char *cookie
,
1005 * Release a shared or exclusive lock on the image.
1007 * @param image the image to unlock
1008 * @param cookie user-defined identifier for the instance of the lock
1009 * @returns 0 on success, negative error code on failure
1010 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
1012 CEPH_RBD_API
int rbd_unlock(rbd_image_t image
, const char *cookie
);
1015 * Release a shared or exclusive lock that was taken by the specified client.
1017 * @param image the image to unlock
1018 * @param client the entity holding the lock (as given by rbd_list_lockers())
1019 * @param cookie user-defined identifier for the instance of the lock to break
1020 * @returns 0 on success, negative error code on failure
1021 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
1023 CEPH_RBD_API
int rbd_break_lock(rbd_image_t image
, const char *client
,
1024 const char *cookie
);
1029 CEPH_RBD_API ssize_t
rbd_read(rbd_image_t image
, uint64_t ofs
, size_t len
,
1032 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
1034 CEPH_RBD_API ssize_t
rbd_read2(rbd_image_t image
, uint64_t ofs
, size_t len
,
1035 char *buf
, int op_flags
);
1036 /* DEPRECATED; use rbd_read_iterate2 */
1037 CEPH_RBD_API
int64_t rbd_read_iterate(rbd_image_t image
, uint64_t ofs
, size_t len
,
1038 int (*cb
)(uint64_t, size_t, const char *, void *),
1042 * iterate read over an image
1044 * Reads each region of the image and calls the callback. If the
1045 * buffer pointer passed to the callback is NULL, the given extent is
1046 * defined to be zeros (a hole). Normally the granularity for the
1047 * callback is the image stripe size.
1049 * @param image image to read
1050 * @param ofs offset to start from
1051 * @param len bytes of source image to cover
1052 * @param cb callback for each region
1053 * @returns 0 success, error otherwise
1055 CEPH_RBD_API
int rbd_read_iterate2(rbd_image_t image
, uint64_t ofs
, uint64_t len
,
1056 int (*cb
)(uint64_t, size_t, const char *, void *),
1059 * get difference between two versions of an image
1061 * This will return the differences between two versions of an image
1062 * via a callback, which gets the offset and length and a flag
1063 * indicating whether the extent exists (1), or is known/defined to
1064 * be zeros (a hole, 0). If the source snapshot name is NULL, we
1065 * interpret that as the beginning of time and return all allocated
1066 * regions of the image. The end version is whatever is currently
1067 * selected for the image handle (either a snapshot or the writeable
1070 * @param fromsnapname start snapshot name, or NULL
1071 * @param ofs start offset
1072 * @param len len in bytes of region to report on
1073 * @param include_parent 1 if full history diff should include parent
1074 * @param whole_object 1 if diff extents should cover whole object
1075 * @param cb callback to call for each allocated region
1076 * @param arg argument to pass to the callback
1077 * @returns 0 on success, or negative error code on error
1079 CEPH_RBD_API
int rbd_diff_iterate(rbd_image_t image
,
1080 const char *fromsnapname
,
1081 uint64_t ofs
, uint64_t len
,
1082 int (*cb
)(uint64_t, size_t, int, void *),
1084 CEPH_RBD_API
int rbd_diff_iterate2(rbd_image_t image
,
1085 const char *fromsnapname
,
1086 uint64_t ofs
, uint64_t len
,
1087 uint8_t include_parent
, uint8_t whole_object
,
1088 int (*cb
)(uint64_t, size_t, int, void *),
1090 CEPH_RBD_API ssize_t
rbd_write(rbd_image_t image
, uint64_t ofs
, size_t len
,
1093 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
1095 CEPH_RBD_API ssize_t
rbd_write2(rbd_image_t image
, uint64_t ofs
, size_t len
,
1096 const char *buf
, int op_flags
);
1097 CEPH_RBD_API
int rbd_discard(rbd_image_t image
, uint64_t ofs
, uint64_t len
);
1098 CEPH_RBD_API ssize_t
rbd_writesame(rbd_image_t image
, uint64_t ofs
, size_t len
,
1099 const char *buf
, size_t data_len
,
1101 CEPH_RBD_API ssize_t
rbd_write_zeroes(rbd_image_t image
, uint64_t ofs
,
1102 size_t len
, int zero_flags
,
1104 CEPH_RBD_API ssize_t
rbd_compare_and_write(rbd_image_t image
, uint64_t ofs
,
1105 size_t len
, const char *cmp_buf
,
1107 uint64_t *mismatch_off
,
1110 CEPH_RBD_API
int rbd_aio_write(rbd_image_t image
, uint64_t off
, size_t len
,
1111 const char *buf
, rbd_completion_t c
);
1114 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
1116 CEPH_RBD_API
int rbd_aio_write2(rbd_image_t image
, uint64_t off
, size_t len
,
1117 const char *buf
, rbd_completion_t c
,
1119 CEPH_RBD_API
int rbd_aio_writev(rbd_image_t image
, const struct iovec
*iov
,
1120 int iovcnt
, uint64_t off
, rbd_completion_t c
);
1121 CEPH_RBD_API
int rbd_aio_read(rbd_image_t image
, uint64_t off
, size_t len
,
1122 char *buf
, rbd_completion_t c
);
1124 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
1126 CEPH_RBD_API
int rbd_aio_read2(rbd_image_t image
, uint64_t off
, size_t len
,
1127 char *buf
, rbd_completion_t c
, int op_flags
);
1128 CEPH_RBD_API
int rbd_aio_readv(rbd_image_t image
, const struct iovec
*iov
,
1129 int iovcnt
, uint64_t off
, rbd_completion_t c
);
1130 CEPH_RBD_API
int rbd_aio_discard(rbd_image_t image
, uint64_t off
, uint64_t len
,
1131 rbd_completion_t c
);
1132 CEPH_RBD_API
int rbd_aio_writesame(rbd_image_t image
, uint64_t off
, size_t len
,
1133 const char *buf
, size_t data_len
,
1134 rbd_completion_t c
, int op_flags
);
1135 CEPH_RBD_API
int rbd_aio_write_zeroes(rbd_image_t image
, uint64_t off
,
1136 size_t len
, rbd_completion_t c
,
1137 int zero_flags
, int op_flags
);
1138 CEPH_RBD_API ssize_t
rbd_aio_compare_and_write(rbd_image_t image
,
1139 uint64_t off
, size_t len
,
1140 const char *cmp_buf
,
1143 uint64_t *mismatch_off
,
1146 CEPH_RBD_API
int rbd_aio_create_completion(void *cb_arg
,
1147 rbd_callback_t complete_cb
,
1148 rbd_completion_t
*c
);
1149 CEPH_RBD_API
int rbd_aio_is_complete(rbd_completion_t c
);
1150 CEPH_RBD_API
int rbd_aio_wait_for_complete(rbd_completion_t c
);
1151 CEPH_RBD_API ssize_t
rbd_aio_get_return_value(rbd_completion_t c
);
1152 CEPH_RBD_API
void *rbd_aio_get_arg(rbd_completion_t c
);
1153 CEPH_RBD_API
void rbd_aio_release(rbd_completion_t c
);
1154 CEPH_RBD_API
int rbd_flush(rbd_image_t image
);
1156 * Start a flush if caching is enabled. Get a callback when
1157 * the currently pending writes are on disk.
1159 * @param image the image to flush writes to
1160 * @param c what to call when flushing is complete
1161 * @returns 0 on success, negative error code on failure
1163 CEPH_RBD_API
int rbd_aio_flush(rbd_image_t image
, rbd_completion_t c
);
1166 * Drop any cached data for an image
1168 * @param image the image to invalidate cached data for
1169 * @returns 0 on success, negative error code on failure
1171 CEPH_RBD_API
int rbd_invalidate_cache(rbd_image_t image
);
1173 CEPH_RBD_API
int rbd_poll_io_events(rbd_image_t image
, rbd_completion_t
*comps
, int numcomp
);
1175 CEPH_RBD_API
int rbd_metadata_get(rbd_image_t image
, const char *key
, char *value
, size_t *val_len
);
1176 CEPH_RBD_API
int rbd_metadata_set(rbd_image_t image
, const char *key
, const char *value
);
1177 CEPH_RBD_API
int rbd_metadata_remove(rbd_image_t image
, const char *key
);
1179 * List all metadatas associated with this image.
1181 * This iterates over all metadatas, key_len and val_len are filled in
1182 * with the number of bytes put into the keys and values buffers.
1184 * If the provided buffers are too short, the required lengths are
1185 * still filled in, but the data is not and -ERANGE is returned.
1186 * Otherwise, the buffers are filled with the keys and values
1187 * of the image, with a '\0' after each.
1189 * @param image which image (and implicitly snapshot) to list clones of
1190 * @param start_after which name to begin listing after
1191 * (use the empty string to start at the beginning)
1192 * @param max the maximum number of names to lis(if 0 means no limit)
1193 * @param keys buffer in which to store pool names
1194 * @param keys_len number of bytes in pools buffer
1195 * @param values buffer in which to store image names
1196 * @param vals_len number of bytes in images buffer
1197 * @returns number of children on success, negative error code on failure
1198 * @returns -ERANGE if either buffer is too short
1200 CEPH_RBD_API
int rbd_metadata_list(rbd_image_t image
, const char *start
, uint64_t max
,
1201 char *keys
, size_t *key_len
, char *values
, size_t *vals_len
);
1203 // RBD image mirroring support functions
1204 CEPH_RBD_API
int rbd_mirror_image_enable(rbd_image_t image
) CEPH_RBD_DEPRECATED
;
1205 CEPH_RBD_API
int rbd_mirror_image_enable2(rbd_image_t image
,
1206 rbd_mirror_image_mode_t mode
);
1207 CEPH_RBD_API
int rbd_mirror_image_disable(rbd_image_t image
, bool force
);
1208 CEPH_RBD_API
int rbd_mirror_image_promote(rbd_image_t image
, bool force
);
1209 CEPH_RBD_API
int rbd_mirror_image_demote(rbd_image_t image
);
1210 CEPH_RBD_API
int rbd_mirror_image_resync(rbd_image_t image
);
1211 CEPH_RBD_API
int rbd_mirror_image_create_snapshot(rbd_image_t image
,
1213 CEPH_RBD_API
int rbd_mirror_image_get_info(rbd_image_t image
,
1214 rbd_mirror_image_info_t
*mirror_image_info
,
1216 CEPH_RBD_API
void rbd_mirror_image_get_info_cleanup(
1217 rbd_mirror_image_info_t
*mirror_image_info
);
1218 CEPH_RBD_API
int rbd_mirror_image_get_mode(rbd_image_t image
,
1219 rbd_mirror_image_mode_t
*mode
);
1221 CEPH_RBD_API
int rbd_mirror_image_get_global_status(
1223 rbd_mirror_image_global_status_t
*mirror_image_global_status
,
1224 size_t status_size
);
1225 CEPH_RBD_API
void rbd_mirror_image_global_status_cleanup(
1226 rbd_mirror_image_global_status_t
*mirror_image_global_status
);
1228 CEPH_RBD_API
int rbd_mirror_image_get_status(
1229 rbd_image_t image
, rbd_mirror_image_status_t
*mirror_image_status
,
1231 CEPH_RBD_DEPRECATED
;
1233 CEPH_RBD_API
int rbd_mirror_image_get_instance_id(rbd_image_t image
,
1235 size_t *id_max_length
);
1236 CEPH_RBD_API
int rbd_aio_mirror_image_promote(rbd_image_t image
, bool force
,
1237 rbd_completion_t c
);
1238 CEPH_RBD_API
int rbd_aio_mirror_image_demote(rbd_image_t image
,
1239 rbd_completion_t c
);
1240 CEPH_RBD_API
int rbd_aio_mirror_image_get_info(rbd_image_t image
,
1241 rbd_mirror_image_info_t
*mirror_image_info
,
1243 rbd_completion_t c
);
1245 CEPH_RBD_API
int rbd_aio_mirror_image_get_global_status(
1247 rbd_mirror_image_global_status_t
*mirror_global_image_status
,
1248 size_t status_size
, rbd_completion_t c
);
1249 CEPH_RBD_API
int rbd_aio_mirror_image_get_status(
1250 rbd_image_t image
, rbd_mirror_image_status_t
*mirror_image_status
,
1251 size_t status_size
, rbd_completion_t c
)
1252 CEPH_RBD_DEPRECATED
;
1254 // RBD groups support functions
1255 CEPH_RBD_API
int rbd_group_create(rados_ioctx_t p
, const char *name
);
1256 CEPH_RBD_API
int rbd_group_remove(rados_ioctx_t p
, const char *name
);
1257 CEPH_RBD_API
int rbd_group_list(rados_ioctx_t p
, char *names
, size_t *size
);
1258 CEPH_RBD_API
int rbd_group_rename(rados_ioctx_t p
, const char *src_name
,
1259 const char *dest_name
);
1260 CEPH_RBD_API
int rbd_group_info_cleanup(rbd_group_info_t
*group_info
,
1261 size_t group_info_size
);
1264 * Register an image metadata change watcher.
1266 * @param image the image to watch
1267 * @param handle where to store the internal id assigned to this watch
1268 * @param watch_cb what to do when a notify is received on this image
1269 * @param arg opaque value to pass to the callback
1270 * @returns 0 on success, negative error code on failure
1272 CEPH_RBD_API
int rbd_update_watch(rbd_image_t image
, uint64_t *handle
,
1273 rbd_update_callback_t watch_cb
, void *arg
);
1276 * Unregister an image watcher.
1278 * @param image the image to unwatch
1279 * @param handle which watch to unregister
1280 * @returns 0 on success, negative error code on failure
1282 CEPH_RBD_API
int rbd_update_unwatch(rbd_image_t image
, uint64_t handle
);
1285 * List any watchers of an image.
1287 * Watchers will be allocated and stored in the passed watchers array. If there
1288 * are more watchers than max_watchers, -ERANGE will be returned and the number
1289 * of watchers will be stored in max_watchers.
1291 * The caller should call rbd_watchers_list_cleanup when finished with the list
1294 * @param image the image to list watchers for.
1295 * @param watchers an array to store watchers in.
1296 * @param max_watchers capacity of the watchers array.
1297 * @returns 0 on success, negative error code on failure.
1298 * @returns -ERANGE if there are too many watchers for the passed array.
1299 * @returns the number of watchers in max_watchers.
1301 CEPH_RBD_API
int rbd_watchers_list(rbd_image_t image
,
1302 rbd_image_watcher_t
*watchers
,
1303 size_t *max_watchers
);
1305 CEPH_RBD_API
void rbd_watchers_list_cleanup(rbd_image_watcher_t
*watchers
,
1306 size_t num_watchers
);
1308 CEPH_RBD_API
int rbd_config_image_list(rbd_image_t image
,
1309 rbd_config_option_t
*options
,
1311 CEPH_RBD_API
void rbd_config_image_list_cleanup(rbd_config_option_t
*options
,
1314 CEPH_RBD_API
int rbd_group_image_add(rados_ioctx_t group_p
,
1315 const char *group_name
,
1316 rados_ioctx_t image_p
,
1317 const char *image_name
);
1318 CEPH_RBD_API
int rbd_group_image_remove(rados_ioctx_t group_p
,
1319 const char *group_name
,
1320 rados_ioctx_t image_p
,
1321 const char *image_name
);
1322 CEPH_RBD_API
int rbd_group_image_remove_by_id(rados_ioctx_t group_p
,
1323 const char *group_name
,
1324 rados_ioctx_t image_p
,
1325 const char *image_id
);
1326 CEPH_RBD_API
int rbd_group_image_list(rados_ioctx_t group_p
,
1327 const char *group_name
,
1328 rbd_group_image_info_t
*images
,
1329 size_t group_image_info_size
,
1330 size_t *num_entries
);
1331 CEPH_RBD_API
int rbd_group_image_list_cleanup(rbd_group_image_info_t
*images
,
1332 size_t group_image_info_size
,
1333 size_t num_entries
);
1335 CEPH_RBD_API
int rbd_group_snap_create(rados_ioctx_t group_p
,
1336 const char *group_name
,
1337 const char *snap_name
);
1338 CEPH_RBD_API
int rbd_group_snap_remove(rados_ioctx_t group_p
,
1339 const char *group_name
,
1340 const char *snap_name
);
1341 CEPH_RBD_API
int rbd_group_snap_rename(rados_ioctx_t group_p
,
1342 const char *group_name
,
1343 const char *old_snap_name
,
1344 const char *new_snap_name
);
1345 CEPH_RBD_API
int rbd_group_snap_list(rados_ioctx_t group_p
,
1346 const char *group_name
,
1347 rbd_group_snap_info_t
*snaps
,
1348 size_t group_snap_info_size
,
1349 size_t *num_entries
);
1350 CEPH_RBD_API
int rbd_group_snap_list_cleanup(rbd_group_snap_info_t
*snaps
,
1351 size_t group_snap_info_size
,
1352 size_t num_entries
);
1353 CEPH_RBD_API
int rbd_group_snap_rollback(rados_ioctx_t group_p
,
1354 const char *group_name
,
1355 const char *snap_name
);
1356 CEPH_RBD_API
int rbd_group_snap_rollback_with_progress(rados_ioctx_t group_p
,
1357 const char *group_name
,
1358 const char *snap_name
,
1359 librbd_progress_fn_t cb
,
1362 CEPH_RBD_API
int rbd_namespace_create(rados_ioctx_t io
,
1363 const char *namespace_name
);
1364 CEPH_RBD_API
int rbd_namespace_remove(rados_ioctx_t io
,
1365 const char *namespace_name
);
1366 CEPH_RBD_API
int rbd_namespace_list(rados_ioctx_t io
, char *namespace_names
,
1368 CEPH_RBD_API
int rbd_namespace_exists(rados_ioctx_t io
,
1369 const char *namespace_name
,
1372 CEPH_RBD_API
int rbd_pool_init(rados_ioctx_t io
, bool force
);
1374 CEPH_RBD_API
void rbd_pool_stats_create(rbd_pool_stats_t
*stats
);
1375 CEPH_RBD_API
void rbd_pool_stats_destroy(rbd_pool_stats_t stats
);
1376 CEPH_RBD_API
int rbd_pool_stats_option_add_uint64(rbd_pool_stats_t stats
,
1378 uint64_t* stat_val
);
1379 CEPH_RBD_API
int rbd_pool_stats_get(rados_ioctx_t io
, rbd_pool_stats_t stats
);
1382 #pragma GCC diagnostic pop
1389 #endif /* CEPH_LIBRBD_H */