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