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