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