]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/rbd/librbd.h
add subtree-ish sources for 12.0.3
[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_LOCKING 1
45 #define LIBRBD_SUPPORTS_INVALIDATE 1
46 #define LIBRBD_SUPPORTS_IOVEC 1
47 #define LIBRBD_SUPPORTS_WATCH 0
48
49 #if __GNUC__ >= 4
50 #define CEPH_RBD_API __attribute__ ((visibility ("default")))
51 #else
52 #define CEPH_RBD_API
53 #endif
54
55 #define RBD_FLAG_OBJECT_MAP_INVALID (1<<0)
56 #define RBD_FLAG_FAST_DIFF_INVALID (1<<1)
57
58 typedef void *rbd_snap_t;
59 typedef void *rbd_image_t;
60 typedef void *rbd_image_options_t;
61
62 typedef void *rbd_completion_t;
63 typedef void (*rbd_callback_t)(rbd_completion_t cb, void *arg);
64
65 typedef int (*librbd_progress_fn_t)(uint64_t offset, uint64_t total, void *ptr);
66
67 typedef void (*rbd_update_callback_t)(void *arg);
68
69 typedef struct {
70 uint64_t id;
71 uint64_t size;
72 const char *name;
73 } rbd_snap_info_t;
74
75 #define RBD_MAX_IMAGE_NAME_SIZE 96
76 #define RBD_MAX_BLOCK_NAME_SIZE 24
77
78 #define RBD_SNAP_REMOVE_UNPROTECT 1 << 0
79 #define RBD_SNAP_REMOVE_FLATTEN 1 << 1
80 #define RBD_SNAP_REMOVE_FORCE (RBD_SNAP_REMOVE_UNPROTECT | RBD_SNAP_REMOVE_FLATTEN)
81
82 /**
83 * These types used to in set_image_notification to indicate the type of event
84 * socket passed in.
85 */
86 enum {
87 EVENT_TYPE_PIPE = 1,
88 EVENT_TYPE_EVENTFD = 2
89 };
90
91 typedef struct {
92 uint64_t size;
93 uint64_t obj_size;
94 uint64_t num_objs;
95 int order;
96 char block_name_prefix[RBD_MAX_BLOCK_NAME_SIZE]; /* deprecated */
97 int64_t parent_pool; /* deprecated */
98 char parent_name[RBD_MAX_IMAGE_NAME_SIZE]; /* deprecated */
99 } rbd_image_info_t;
100
101 typedef enum {
102 RBD_MIRROR_MODE_DISABLED, /* mirroring is disabled */
103 RBD_MIRROR_MODE_IMAGE, /* mirroring enabled on a per-image basis */
104 RBD_MIRROR_MODE_POOL /* mirroring enabled on all journaled images */
105 } rbd_mirror_mode_t;
106
107 typedef struct {
108 char *uuid;
109 char *cluster_name;
110 char *client_name;
111 } rbd_mirror_peer_t;
112
113 typedef enum {
114 RBD_MIRROR_IMAGE_DISABLING = 0,
115 RBD_MIRROR_IMAGE_ENABLED = 1,
116 RBD_MIRROR_IMAGE_DISABLED = 2
117 } rbd_mirror_image_state_t;
118
119 typedef struct {
120 char *global_id;
121 rbd_mirror_image_state_t state;
122 bool primary;
123 } rbd_mirror_image_info_t;
124
125 typedef enum {
126 MIRROR_IMAGE_STATUS_STATE_UNKNOWN = 0,
127 MIRROR_IMAGE_STATUS_STATE_ERROR = 1,
128 MIRROR_IMAGE_STATUS_STATE_SYNCING = 2,
129 MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY = 3,
130 MIRROR_IMAGE_STATUS_STATE_REPLAYING = 4,
131 MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY = 5,
132 MIRROR_IMAGE_STATUS_STATE_STOPPED = 6,
133 } rbd_mirror_image_status_state_t;
134
135 typedef struct {
136 char *name;
137 rbd_mirror_image_info_t info;
138 rbd_mirror_image_status_state_t state;
139 char *description;
140 time_t last_update;
141 bool up;
142 } rbd_mirror_image_status_t;
143
144 typedef enum {
145 GROUP_IMAGE_STATE_ATTACHED,
146 GROUP_IMAGE_STATE_INCOMPLETE
147 } rbd_group_image_state_t;
148
149 typedef struct {
150 char *name;
151 int64_t pool;
152 } rbd_group_image_spec_t;
153
154 typedef struct {
155 rbd_group_image_spec_t spec;
156 rbd_group_image_state_t state;
157 } rbd_group_image_status_t;
158
159 typedef struct {
160 char *name;
161 int64_t pool;
162 } rbd_group_spec_t;
163
164 typedef enum {
165 RBD_LOCK_MODE_EXCLUSIVE = 0,
166 RBD_LOCK_MODE_SHARED = 1,
167 } rbd_lock_mode_t;
168
169 CEPH_RBD_API void rbd_version(int *major, int *minor, int *extra);
170
171 /* image options */
172 enum {
173 RBD_IMAGE_OPTION_FORMAT = 0,
174 RBD_IMAGE_OPTION_FEATURES = 1,
175 RBD_IMAGE_OPTION_ORDER = 2,
176 RBD_IMAGE_OPTION_STRIPE_UNIT = 3,
177 RBD_IMAGE_OPTION_STRIPE_COUNT = 4,
178 RBD_IMAGE_OPTION_JOURNAL_ORDER = 5,
179 RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH = 6,
180 RBD_IMAGE_OPTION_JOURNAL_POOL = 7,
181 RBD_IMAGE_OPTION_FEATURES_SET = 8,
182 RBD_IMAGE_OPTION_FEATURES_CLEAR = 9,
183 RBD_IMAGE_OPTION_DATA_POOL = 10
184 };
185
186 typedef enum {
187 RBD_TRASH_IMAGE_SOURCE_USER = 0,
188 RBD_TRASH_IMAGE_SOURCE_MIRRORING = 1
189 } rbd_trash_image_source_t;
190
191 typedef struct {
192 char *id;
193 char *name;
194 rbd_trash_image_source_t source;
195 time_t deletion_time;
196 time_t deferment_end_time;
197 } rbd_trash_image_info_t;
198
199 CEPH_RBD_API void rbd_image_options_create(rbd_image_options_t* opts);
200 CEPH_RBD_API void rbd_image_options_destroy(rbd_image_options_t opts);
201 CEPH_RBD_API int rbd_image_options_set_string(rbd_image_options_t opts,
202 int optname, const char* optval);
203 CEPH_RBD_API int rbd_image_options_set_uint64(rbd_image_options_t opts,
204 int optname, uint64_t optval);
205 CEPH_RBD_API int rbd_image_options_get_string(rbd_image_options_t opts,
206 int optname, char* optval,
207 size_t maxlen);
208 CEPH_RBD_API int rbd_image_options_get_uint64(rbd_image_options_t opts,
209 int optname, uint64_t* optval);
210 CEPH_RBD_API int rbd_image_options_is_set(rbd_image_options_t opts,
211 int optname, bool* is_set);
212 CEPH_RBD_API int rbd_image_options_unset(rbd_image_options_t opts, int optname);
213 CEPH_RBD_API void rbd_image_options_clear(rbd_image_options_t opts);
214 CEPH_RBD_API int rbd_image_options_is_empty(rbd_image_options_t opts);
215
216 /* images */
217 CEPH_RBD_API int rbd_list(rados_ioctx_t io, char *names, size_t *size);
218 CEPH_RBD_API int rbd_create(rados_ioctx_t io, const char *name, uint64_t size,
219 int *order);
220 CEPH_RBD_API int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size,
221 uint64_t features, int *order);
222 /**
223 * create new rbd image
224 *
225 * The stripe_unit must be a factor of the object size (1 << order).
226 * The stripe_count can be one (no intra-object striping) or greater
227 * than one. The RBD_FEATURE_STRIPINGV2 must be specified if the
228 * stripe_unit != the object size and the stripe_count is != 1.
229 *
230 * @param io ioctx
231 * @param name image name
232 * @param size image size in bytes
233 * @param features initial feature bits
234 * @param order object/block size, as a power of two (object size == 1 << order)
235 * @param stripe_unit stripe unit size, in bytes.
236 * @param stripe_count number of objects to stripe over before looping
237 * @return 0 on success, or negative error code
238 */
239 CEPH_RBD_API int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size,
240 uint64_t features, int *order,
241 uint64_t stripe_unit, uint64_t stripe_count);
242 CEPH_RBD_API int rbd_create4(rados_ioctx_t io, const char *name, uint64_t size,
243 rbd_image_options_t opts);
244 CEPH_RBD_API int rbd_clone(rados_ioctx_t p_ioctx, const char *p_name,
245 const char *p_snapname, rados_ioctx_t c_ioctx,
246 const char *c_name, uint64_t features, int *c_order);
247 CEPH_RBD_API int rbd_clone2(rados_ioctx_t p_ioctx, const char *p_name,
248 const char *p_snapname, rados_ioctx_t c_ioctx,
249 const char *c_name, uint64_t features, int *c_order,
250 uint64_t stripe_unit, int stripe_count);
251 CEPH_RBD_API int rbd_clone3(rados_ioctx_t p_ioctx, const char *p_name,
252 const char *p_snapname, rados_ioctx_t c_ioctx,
253 const char *c_name, rbd_image_options_t c_opts);
254 CEPH_RBD_API int rbd_remove(rados_ioctx_t io, const char *name);
255 CEPH_RBD_API int rbd_remove_with_progress(rados_ioctx_t io, const char *name,
256 librbd_progress_fn_t cb,
257 void *cbdata);
258 CEPH_RBD_API int rbd_rename(rados_ioctx_t src_io_ctx, const char *srcname,
259 const char *destname);
260
261 CEPH_RBD_API int rbd_trash_move(rados_ioctx_t io, const char *name,
262 uint64_t delay);
263 CEPH_RBD_API int rbd_trash_get(rados_ioctx_t io, const char *id,
264 rbd_trash_image_info_t *info);
265 CEPH_RBD_API void rbd_trash_get_cleanup(rbd_trash_image_info_t *info);
266 CEPH_RBD_API int rbd_trash_list(rados_ioctx_t io,
267 rbd_trash_image_info_t *trash_entries,
268 size_t *num_entries);
269 CEPH_RBD_API void rbd_trash_list_cleanup(rbd_trash_image_info_t *trash_entries,
270 size_t num_entries);
271 CEPH_RBD_API int rbd_trash_remove(rados_ioctx_t io, const char *id, bool force);
272 CEPH_RBD_API int rbd_trash_remove_with_progress(rados_ioctx_t io, const char *id,
273 bool force, librbd_progress_fn_t cb,
274 void *cbdata);
275 CEPH_RBD_API int rbd_trash_restore(rados_ioctx_t io, const char *id,
276 const char *name);
277
278 /* pool mirroring */
279 CEPH_RBD_API int rbd_mirror_mode_get(rados_ioctx_t io_ctx,
280 rbd_mirror_mode_t *mirror_mode);
281 CEPH_RBD_API int rbd_mirror_mode_set(rados_ioctx_t io_ctx,
282 rbd_mirror_mode_t mirror_mode);
283 CEPH_RBD_API int rbd_mirror_peer_add(rados_ioctx_t io_ctx,
284 char *uuid, size_t uuid_max_length,
285 const char *cluster_name,
286 const char *client_name);
287 CEPH_RBD_API int rbd_mirror_peer_remove(rados_ioctx_t io_ctx,
288 const char *uuid);
289 CEPH_RBD_API int rbd_mirror_peer_list(rados_ioctx_t io_ctx,
290 rbd_mirror_peer_t *peers, int *max_peers);
291 CEPH_RBD_API void rbd_mirror_peer_list_cleanup(rbd_mirror_peer_t *peers,
292 int max_peers);
293 CEPH_RBD_API int rbd_mirror_peer_set_client(rados_ioctx_t io_ctx,
294 const char *uuid,
295 const char *client_name);
296 CEPH_RBD_API int rbd_mirror_peer_set_cluster(rados_ioctx_t io_ctx,
297 const char *uuid,
298 const char *cluster_name);
299 CEPH_RBD_API int rbd_mirror_image_status_list(rados_ioctx_t io_ctx,
300 const char *start_id, size_t max,
301 char **image_ids,
302 rbd_mirror_image_status_t *images,
303 size_t *len);
304 CEPH_RBD_API void rbd_mirror_image_status_list_cleanup(char **image_ids,
305 rbd_mirror_image_status_t *images, size_t len);
306 CEPH_RBD_API int rbd_mirror_image_status_summary(rados_ioctx_t io_ctx,
307 rbd_mirror_image_status_state_t *states, int *counts, size_t *maxlen);
308
309 CEPH_RBD_API int rbd_open(rados_ioctx_t io, const char *name,
310 rbd_image_t *image, const char *snap_name);
311 CEPH_RBD_API int rbd_open_by_id(rados_ioctx_t io, const char *id,
312 rbd_image_t *image, const char *snap_name);
313
314 CEPH_RBD_API int rbd_aio_open(rados_ioctx_t io, const char *name,
315 rbd_image_t *image, const char *snap_name,
316 rbd_completion_t c);
317 CEPH_RBD_API int rbd_aio_open_by_id(rados_ioctx_t io, const char *id,
318 rbd_image_t *image, const char *snap_name,
319 rbd_completion_t c);
320
321 /**
322 * Open an image in read-only mode.
323 *
324 * This is intended for use by clients that cannot write to a block
325 * device due to cephx restrictions. There will be no watch
326 * established on the header object, since a watch is a write. This
327 * means the metadata reported about this image (parents, snapshots,
328 * size, etc.) may become stale. This should not be used for
329 * long-running operations, unless you can be sure that one of these
330 * properties changing is safe.
331 *
332 * Attempting to write to a read-only image will return -EROFS.
333 *
334 * @param io ioctx to determine the pool the image is in
335 * @param name image name
336 * @param image where to store newly opened image handle
337 * @param snap_name name of snapshot to open at, or NULL for no snapshot
338 * @returns 0 on success, negative error code on failure
339 */
340 CEPH_RBD_API int rbd_open_read_only(rados_ioctx_t io, const char *name,
341 rbd_image_t *image, const char *snap_name);
342 CEPH_RBD_API int rbd_open_by_id_read_only(rados_ioctx_t io, const char *id,
343 rbd_image_t *image, const char *snap_name);
344 CEPH_RBD_API int rbd_aio_open_read_only(rados_ioctx_t io, const char *name,
345 rbd_image_t *image, const char *snap_name,
346 rbd_completion_t c);
347 CEPH_RBD_API int rbd_aio_open_by_id_read_only(rados_ioctx_t io, const char *id,
348 rbd_image_t *image, const char *snap_name,
349 rbd_completion_t c);
350 CEPH_RBD_API int rbd_close(rbd_image_t image);
351 CEPH_RBD_API int rbd_aio_close(rbd_image_t image, rbd_completion_t c);
352 CEPH_RBD_API int rbd_resize(rbd_image_t image, uint64_t size);
353 CEPH_RBD_API int rbd_resize2(rbd_image_t image, uint64_t size, bool allow_shrink,
354 librbd_progress_fn_t cb, void *cbdata);
355 CEPH_RBD_API int rbd_resize_with_progress(rbd_image_t image, uint64_t size,
356 librbd_progress_fn_t cb, void *cbdata);
357 CEPH_RBD_API int rbd_stat(rbd_image_t image, rbd_image_info_t *info,
358 size_t infosize);
359 CEPH_RBD_API int rbd_get_old_format(rbd_image_t image, uint8_t *old);
360 CEPH_RBD_API int rbd_get_size(rbd_image_t image, uint64_t *size);
361 CEPH_RBD_API int rbd_get_features(rbd_image_t image, uint64_t *features);
362 CEPH_RBD_API int rbd_update_features(rbd_image_t image, uint64_t features,
363 uint8_t enabled);
364 CEPH_RBD_API int rbd_get_stripe_unit(rbd_image_t image, uint64_t *stripe_unit);
365 CEPH_RBD_API int rbd_get_stripe_count(rbd_image_t image,
366 uint64_t *stripe_count);
367 CEPH_RBD_API int rbd_get_overlap(rbd_image_t image, uint64_t *overlap);
368 CEPH_RBD_API int rbd_get_id(rbd_image_t image, char *id, size_t id_len);
369 CEPH_RBD_API int rbd_get_block_name_prefix(rbd_image_t image,
370 char *prefix, size_t prefix_len);
371 CEPH_RBD_API int64_t rbd_get_data_pool_id(rbd_image_t image);
372 CEPH_RBD_API int rbd_get_parent_info(rbd_image_t image,
373 char *parent_poolname, size_t ppoolnamelen,
374 char *parent_name, size_t pnamelen,
375 char *parent_snapname,
376 size_t psnapnamelen);
377 CEPH_RBD_API int rbd_get_parent_info2(rbd_image_t image,
378 char *parent_poolname,
379 size_t ppoolnamelen,
380 char *parent_name, size_t pnamelen,
381 char *parent_id, size_t pidlen,
382 char *parent_snapname,
383 size_t psnapnamelen);
384 CEPH_RBD_API int rbd_get_flags(rbd_image_t image, uint64_t *flags);
385 CEPH_RBD_API int rbd_set_image_notification(rbd_image_t image, int fd, int type);
386
387 /* exclusive lock feature */
388 CEPH_RBD_API int rbd_is_exclusive_lock_owner(rbd_image_t image, int *is_owner);
389 CEPH_RBD_API int rbd_lock_acquire(rbd_image_t image, rbd_lock_mode_t lock_mode);
390 CEPH_RBD_API int rbd_lock_release(rbd_image_t image);
391 CEPH_RBD_API int rbd_lock_get_owners(rbd_image_t image,
392 rbd_lock_mode_t *lock_mode,
393 char **lock_owners,
394 size_t *max_lock_owners);
395 CEPH_RBD_API void rbd_lock_get_owners_cleanup(char **lock_owners,
396 size_t lock_owner_count);
397 CEPH_RBD_API int rbd_lock_break(rbd_image_t image, rbd_lock_mode_t lock_mode,
398 const char *lock_owner);
399
400 /* object map feature */
401 CEPH_RBD_API int rbd_rebuild_object_map(rbd_image_t image,
402 librbd_progress_fn_t cb, void *cbdata);
403
404 CEPH_RBD_API int rbd_copy(rbd_image_t image, rados_ioctx_t dest_io_ctx,
405 const char *destname);
406 CEPH_RBD_API int rbd_copy2(rbd_image_t src, rbd_image_t dest);
407 CEPH_RBD_API int rbd_copy3(rbd_image_t src, rados_ioctx_t dest_io_ctx,
408 const char *destname, rbd_image_options_t dest_opts);
409 CEPH_RBD_API int rbd_copy4(rbd_image_t src, rados_ioctx_t dest_io_ctx,
410 const char *destname, rbd_image_options_t dest_opts,
411 size_t sparse_size);
412 CEPH_RBD_API int rbd_copy_with_progress(rbd_image_t image, rados_ioctx_t dest_p,
413 const char *destname,
414 librbd_progress_fn_t cb, void *cbdata);
415 CEPH_RBD_API int rbd_copy_with_progress2(rbd_image_t src, rbd_image_t dest,
416 librbd_progress_fn_t cb, void *cbdata);
417 CEPH_RBD_API int rbd_copy_with_progress3(rbd_image_t image,
418 rados_ioctx_t dest_p,
419 const char *destname,
420 rbd_image_options_t dest_opts,
421 librbd_progress_fn_t cb, void *cbdata);
422 CEPH_RBD_API int rbd_copy_with_progress4(rbd_image_t image,
423 rados_ioctx_t dest_p,
424 const char *destname,
425 rbd_image_options_t dest_opts,
426 librbd_progress_fn_t cb, void *cbdata,
427 size_t sparse_size);
428
429 /* snapshots */
430 CEPH_RBD_API int rbd_snap_list(rbd_image_t image, rbd_snap_info_t *snaps,
431 int *max_snaps);
432 CEPH_RBD_API void rbd_snap_list_end(rbd_snap_info_t *snaps);
433 CEPH_RBD_API int rbd_snap_create(rbd_image_t image, const char *snapname);
434 CEPH_RBD_API int rbd_snap_remove(rbd_image_t image, const char *snapname);
435 CEPH_RBD_API int rbd_snap_remove2(rbd_image_t image, const char *snap_name, uint32_t flags,
436 librbd_progress_fn_t cb, void *cbdata);
437 CEPH_RBD_API int rbd_snap_rollback(rbd_image_t image, const char *snapname);
438 CEPH_RBD_API int rbd_snap_rollback_with_progress(rbd_image_t image,
439 const char *snapname,
440 librbd_progress_fn_t cb,
441 void *cbdata);
442 CEPH_RBD_API int rbd_snap_rename(rbd_image_t image, const char *snapname,
443 const char* dstsnapsname);
444 /**
445 * Prevent a snapshot from being deleted until it is unprotected.
446 *
447 * @param snap_name which snapshot to protect
448 * @returns 0 on success, negative error code on failure
449 * @returns -EBUSY if snap is already protected
450 */
451 CEPH_RBD_API int rbd_snap_protect(rbd_image_t image, const char *snap_name);
452 /**
453 * Allow a snaphshot to be deleted.
454 *
455 * @param snap_name which snapshot to unprotect
456 * @returns 0 on success, negative error code on failure
457 * @returns -EINVAL if snap is not protected
458 */
459 CEPH_RBD_API int rbd_snap_unprotect(rbd_image_t image, const char *snap_name);
460 /**
461 * Determine whether a snapshot is protected.
462 *
463 * @param snap_name which snapshot query
464 * @param is_protected where to store the result (0 or 1)
465 * @returns 0 on success, negative error code on failure
466 */
467 CEPH_RBD_API int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,
468 int *is_protected);
469 /**
470 * Get the current snapshot limit for an image. If no limit is set,
471 * UINT64_MAX is returned.
472 *
473 * @param limit pointer where the limit will be stored on success
474 * @returns 0 on success, negative error code on failure
475 */
476 CEPH_RBD_API int rbd_snap_get_limit(rbd_image_t image, uint64_t *limit);
477
478 /**
479 * Set a limit for the number of snapshots that may be taken of an image.
480 *
481 * @param limit the maximum number of snapshots allowed in the future.
482 * @returns 0 on success, negative error code on failure
483 */
484 CEPH_RBD_API int rbd_snap_set_limit(rbd_image_t image, uint64_t limit);
485
486 /**
487 * Get the timestamp of a snapshot for an image.
488 *
489 * @param snap_id the snap id of a snapshot of input image.
490 * @param timestamp the timestamp of input snapshot.
491 * @returns 0 on success, negative error code on failure
492 */
493 CEPH_RBD_API int rbd_snap_get_timestamp(rbd_image_t image, uint64_t snap_id, struct timespec *timestamp);
494
495 CEPH_RBD_API int rbd_snap_set(rbd_image_t image, const char *snapname);
496
497 CEPH_RBD_API int rbd_flatten(rbd_image_t image);
498
499 CEPH_RBD_API int rbd_flatten_with_progress(rbd_image_t image,
500 librbd_progress_fn_t cb,
501 void *cbdata);
502
503 /**
504 * List all images that are cloned from the image at the
505 * snapshot that is set via rbd_snap_set().
506 *
507 * This iterates over all pools, so it should be run by a user with
508 * read access to all of them. pools_len and images_len are filled in
509 * with the number of bytes put into the pools and images buffers.
510 *
511 * If the provided buffers are too short, the required lengths are
512 * still filled in, but the data is not and -ERANGE is returned.
513 * Otherwise, the buffers are filled with the pool and image names
514 * of the children, with a '\0' after each.
515 *
516 * @param image which image (and implicitly snapshot) to list clones of
517 * @param pools buffer in which to store pool names
518 * @param pools_len number of bytes in pools buffer
519 * @param images buffer in which to store image names
520 * @param images_len number of bytes in images buffer
521 * @returns number of children on success, negative error code on failure
522 * @returns -ERANGE if either buffer is too short
523 */
524 CEPH_RBD_API ssize_t rbd_list_children(rbd_image_t image, char *pools,
525 size_t *pools_len, char *images,
526 size_t *images_len);
527
528 /**
529 * @defgroup librbd_h_locking Advisory Locking
530 *
531 * An rbd image may be locking exclusively, or shared, to facilitate
532 * e.g. live migration where the image may be open in two places at once.
533 * These locks are intended to guard against more than one client
534 * writing to an image without coordination. They don't need to
535 * be used for snapshots, since snapshots are read-only.
536 *
537 * Currently locks only guard against locks being acquired.
538 * They do not prevent anything else.
539 *
540 * A locker is identified by the internal rados client id of the
541 * holder and a user-defined cookie. This (client id, cookie) pair
542 * must be unique for each locker.
543 *
544 * A shared lock also has a user-defined tag associated with it. Each
545 * additional shared lock must specify the same tag or lock
546 * acquisition will fail. This can be used by e.g. groups of hosts
547 * using a clustered filesystem on top of an rbd image to make sure
548 * they're accessing the correct image.
549 *
550 * @{
551 */
552 /**
553 * List clients that have locked the image and information about the lock.
554 *
555 * The number of bytes required in each buffer is put in the
556 * corresponding size out parameter. If any of the provided buffers
557 * are too short, -ERANGE is returned after these sizes are filled in.
558 *
559 * @param exclusive where to store whether the lock is exclusive (1) or shared (0)
560 * @param tag where to store the tag associated with the image
561 * @param tag_len number of bytes in tag buffer
562 * @param clients buffer in which locker clients are stored, separated by '\0'
563 * @param clients_len number of bytes in the clients buffer
564 * @param cookies buffer in which locker cookies are stored, separated by '\0'
565 * @param cookies_len number of bytes in the cookies buffer
566 * @param addrs buffer in which locker addresses are stored, separated by '\0'
567 * @param addrs_len number of bytes in the clients buffer
568 * @returns number of lockers on success, negative error code on failure
569 * @returns -ERANGE if any of the buffers are too short
570 */
571 CEPH_RBD_API ssize_t rbd_list_lockers(rbd_image_t image, int *exclusive,
572 char *tag, size_t *tag_len,
573 char *clients, size_t *clients_len,
574 char *cookies, size_t *cookies_len,
575 char *addrs, size_t *addrs_len);
576
577 /**
578 * Take an exclusive lock on the image.
579 *
580 * @param image the image to lock
581 * @param cookie user-defined identifier for this instance of the lock
582 * @returns 0 on success, negative error code on failure
583 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
584 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
585 */
586 CEPH_RBD_API int rbd_lock_exclusive(rbd_image_t image, const char *cookie);
587
588 /**
589 * Take a shared lock on the image.
590 *
591 * Other clients may also take a shared lock, as lock as they use the
592 * same tag.
593 *
594 * @param image the image to lock
595 * @param cookie user-defined identifier for this instance of the lock
596 * @param tag user-defined identifier for this shared use of the lock
597 * @returns 0 on success, negative error code on failure
598 * @returns -EBUSY if the lock is already held by another (client, cookie) pair
599 * @returns -EEXIST if the lock is already held by the same (client, cookie) pair
600 */
601 CEPH_RBD_API int rbd_lock_shared(rbd_image_t image, const char *cookie,
602 const char *tag);
603
604 /**
605 * Release a shared or exclusive lock on the image.
606 *
607 * @param image the image to unlock
608 * @param cookie user-defined identifier for the instance of the lock
609 * @returns 0 on success, negative error code on failure
610 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
611 */
612 CEPH_RBD_API int rbd_unlock(rbd_image_t image, const char *cookie);
613
614 /**
615 * Release a shared or exclusive lock that was taken by the specified client.
616 *
617 * @param image the image to unlock
618 * @param client the entity holding the lock (as given by rbd_list_lockers())
619 * @param cookie user-defined identifier for the instance of the lock to break
620 * @returns 0 on success, negative error code on failure
621 * @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
622 */
623 CEPH_RBD_API int rbd_break_lock(rbd_image_t image, const char *client,
624 const char *cookie);
625
626 /** @} locking */
627
628 /* I/O */
629 CEPH_RBD_API ssize_t rbd_read(rbd_image_t image, uint64_t ofs, size_t len,
630 char *buf);
631 /*
632 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
633 */
634 CEPH_RBD_API ssize_t rbd_read2(rbd_image_t image, uint64_t ofs, size_t len,
635 char *buf, int op_flags);
636 /* DEPRECATED; use rbd_read_iterate2 */
637 CEPH_RBD_API int64_t rbd_read_iterate(rbd_image_t image, uint64_t ofs, size_t len,
638 int (*cb)(uint64_t, size_t, const char *, void *),
639 void *arg);
640
641 /**
642 * iterate read over an image
643 *
644 * Reads each region of the image and calls the callback. If the
645 * buffer pointer passed to the callback is NULL, the given extent is
646 * defined to be zeros (a hole). Normally the granularity for the
647 * callback is the image stripe size.
648 *
649 * @param image image to read
650 * @param ofs offset to start from
651 * @param len bytes of source image to cover
652 * @param cb callback for each region
653 * @returns 0 success, error otherwise
654 */
655 CEPH_RBD_API int rbd_read_iterate2(rbd_image_t image, uint64_t ofs, uint64_t len,
656 int (*cb)(uint64_t, size_t, const char *, void *),
657 void *arg);
658 /**
659 * get difference between two versions of an image
660 *
661 * This will return the differences between two versions of an image
662 * via a callback, which gets the offset and length and a flag
663 * indicating whether the extent exists (1), or is known/defined to
664 * be zeros (a hole, 0). If the source snapshot name is NULL, we
665 * interpret that as the beginning of time and return all allocated
666 * regions of the image. The end version is whatever is currently
667 * selected for the image handle (either a snapshot or the writeable
668 * head).
669 *
670 * @param fromsnapname start snapshot name, or NULL
671 * @param ofs start offset
672 * @param len len in bytes of region to report on
673 * @param include_parent 1 if full history diff should include parent
674 * @param whole_object 1 if diff extents should cover whole object
675 * @param cb callback to call for each allocated region
676 * @param arg argument to pass to the callback
677 * @returns 0 on success, or negative error code on error
678 */
679 CEPH_RBD_API int rbd_diff_iterate(rbd_image_t image,
680 const char *fromsnapname,
681 uint64_t ofs, uint64_t len,
682 int (*cb)(uint64_t, size_t, int, void *),
683 void *arg);
684 CEPH_RBD_API int rbd_diff_iterate2(rbd_image_t image,
685 const char *fromsnapname,
686 uint64_t ofs, uint64_t len,
687 uint8_t include_parent, uint8_t whole_object,
688 int (*cb)(uint64_t, size_t, int, void *),
689 void *arg);
690 CEPH_RBD_API ssize_t rbd_write(rbd_image_t image, uint64_t ofs, size_t len,
691 const char *buf);
692 /*
693 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
694 */
695 CEPH_RBD_API ssize_t rbd_write2(rbd_image_t image, uint64_t ofs, size_t len,
696 const char *buf, int op_flags);
697 CEPH_RBD_API int rbd_discard(rbd_image_t image, uint64_t ofs, uint64_t len);
698 CEPH_RBD_API ssize_t rbd_writesame(rbd_image_t image, uint64_t ofs, size_t len,
699 const char *buf, size_t data_len, int op_flags);
700 CEPH_RBD_API int rbd_aio_write(rbd_image_t image, uint64_t off, size_t len,
701 const char *buf, rbd_completion_t c);
702
703 /*
704 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
705 */
706 CEPH_RBD_API int rbd_aio_write2(rbd_image_t image, uint64_t off, size_t len,
707 const char *buf, rbd_completion_t c,
708 int op_flags);
709 CEPH_RBD_API int rbd_aio_writev(rbd_image_t image, const struct iovec *iov,
710 int iovcnt, uint64_t off, rbd_completion_t c);
711 CEPH_RBD_API int rbd_aio_read(rbd_image_t image, uint64_t off, size_t len,
712 char *buf, rbd_completion_t c);
713 /*
714 * @param op_flags: see librados.h constants beginning with LIBRADOS_OP_FLAG
715 */
716 CEPH_RBD_API int rbd_aio_read2(rbd_image_t image, uint64_t off, size_t len,
717 char *buf, rbd_completion_t c, int op_flags);
718 CEPH_RBD_API int rbd_aio_readv(rbd_image_t image, const struct iovec *iov,
719 int iovcnt, uint64_t off, rbd_completion_t c);
720 CEPH_RBD_API int rbd_aio_discard(rbd_image_t image, uint64_t off, uint64_t len,
721 rbd_completion_t c);
722 CEPH_RBD_API int rbd_aio_writesame(rbd_image_t image, uint64_t off, size_t len,
723 const char *buf, size_t data_len,
724 rbd_completion_t c, int op_flags);
725
726 CEPH_RBD_API int rbd_aio_create_completion(void *cb_arg,
727 rbd_callback_t complete_cb,
728 rbd_completion_t *c);
729 CEPH_RBD_API int rbd_aio_is_complete(rbd_completion_t c);
730 CEPH_RBD_API int rbd_aio_wait_for_complete(rbd_completion_t c);
731 CEPH_RBD_API ssize_t rbd_aio_get_return_value(rbd_completion_t c);
732 CEPH_RBD_API void *rbd_aio_get_arg(rbd_completion_t c);
733 CEPH_RBD_API void rbd_aio_release(rbd_completion_t c);
734 CEPH_RBD_API int rbd_flush(rbd_image_t image);
735 /**
736 * Start a flush if caching is enabled. Get a callback when
737 * the currently pending writes are on disk.
738 *
739 * @param image the image to flush writes to
740 * @param c what to call when flushing is complete
741 * @returns 0 on success, negative error code on failure
742 */
743 CEPH_RBD_API int rbd_aio_flush(rbd_image_t image, rbd_completion_t c);
744
745 /**
746 * Drop any cached data for an image
747 *
748 * @param image the image to invalidate cached data for
749 * @returns 0 on success, negative error code on failure
750 */
751 CEPH_RBD_API int rbd_invalidate_cache(rbd_image_t image);
752
753 CEPH_RBD_API int rbd_poll_io_events(rbd_image_t image, rbd_completion_t *comps, int numcomp);
754
755 CEPH_RBD_API int rbd_metadata_get(rbd_image_t image, const char *key, char *value, size_t *val_len);
756 CEPH_RBD_API int rbd_metadata_set(rbd_image_t image, const char *key, const char *value);
757 CEPH_RBD_API int rbd_metadata_remove(rbd_image_t image, const char *key);
758 /**
759 * List all metadatas associated with this image.
760 *
761 * This iterates over all metadatas, key_len and val_len are filled in
762 * with the number of bytes put into the keys and values buffers.
763 *
764 * If the provided buffers are too short, the required lengths are
765 * still filled in, but the data is not and -ERANGE is returned.
766 * Otherwise, the buffers are filled with the keys and values
767 * of the image, with a '\0' after each.
768 *
769 * @param image which image (and implicitly snapshot) to list clones of
770 * @param start_after which name to begin listing after
771 * (use the empty string to start at the beginning)
772 * @param max the maximum number of names to lis(if 0 means no limit)
773 * @param keys buffer in which to store pool names
774 * @param keys_len number of bytes in pools buffer
775 * @param values buffer in which to store image names
776 * @param vals_len number of bytes in images buffer
777 * @returns number of children on success, negative error code on failure
778 * @returns -ERANGE if either buffer is too short
779 */
780 CEPH_RBD_API int rbd_metadata_list(rbd_image_t image, const char *start, uint64_t max,
781 char *keys, size_t *key_len, char *values, size_t *vals_len);
782
783 // RBD image mirroring support functions
784 CEPH_RBD_API int rbd_mirror_image_enable(rbd_image_t image);
785 CEPH_RBD_API int rbd_mirror_image_disable(rbd_image_t image, bool force);
786 CEPH_RBD_API int rbd_mirror_image_promote(rbd_image_t image, bool force);
787 CEPH_RBD_API int rbd_mirror_image_demote(rbd_image_t image);
788 CEPH_RBD_API int rbd_mirror_image_resync(rbd_image_t image);
789 CEPH_RBD_API int rbd_mirror_image_get_info(rbd_image_t image,
790 rbd_mirror_image_info_t *mirror_image_info,
791 size_t info_size);
792 CEPH_RBD_API int rbd_mirror_image_get_status(rbd_image_t image,
793 rbd_mirror_image_status_t *mirror_image_status,
794 size_t status_size);
795 CEPH_RBD_API int rbd_aio_mirror_image_promote(rbd_image_t image, bool force,
796 rbd_completion_t c);
797 CEPH_RBD_API int rbd_aio_mirror_image_demote(rbd_image_t image,
798 rbd_completion_t c);
799 CEPH_RBD_API int rbd_aio_mirror_image_get_info(rbd_image_t image,
800 rbd_mirror_image_info_t *mirror_image_info,
801 size_t info_size,
802 rbd_completion_t c);
803 CEPH_RBD_API int rbd_aio_mirror_image_get_status(rbd_image_t image,
804 rbd_mirror_image_status_t *mirror_image_status,
805 size_t status_size,
806 rbd_completion_t c);
807
808 // RBD consistency groups support functions
809 CEPH_RBD_API int rbd_group_create(rados_ioctx_t p, const char *name);
810 CEPH_RBD_API int rbd_group_remove(rados_ioctx_t p, const char *name);
811 CEPH_RBD_API int rbd_group_list(rados_ioctx_t p, char *names, size_t *size);
812
813 /**
814 * Register an image metadata change watcher.
815 *
816 * @param image the image to watch
817 * @param handle where to store the internal id assigned to this watch
818 * @param watch_cb what to do when a notify is received on this image
819 * @param arg opaque value to pass to the callback
820 * @returns 0 on success, negative error code on failure
821 */
822 CEPH_RBD_API int rbd_update_watch(rbd_image_t image, uint64_t *handle,
823 rbd_update_callback_t watch_cb, void *arg);
824
825 /**
826 * Unregister an image watcher.
827 *
828 * @param image the image to unwatch
829 * @param handle which watch to unregister
830 * @returns 0 on success, negative error code on failure
831 */
832 CEPH_RBD_API int rbd_update_unwatch(rbd_image_t image, uint64_t handle);
833
834
835 CEPH_RBD_API int rbd_group_image_add(
836 rados_ioctx_t group_p, const char *group_name,
837 rados_ioctx_t image_p, const char *image_name);
838 CEPH_RBD_API int rbd_group_image_remove(
839 rados_ioctx_t group_p, const char *group_name,
840 rados_ioctx_t image_p, const char *image_name);
841 CEPH_RBD_API int rbd_group_image_remove_by_id(
842 rados_ioctx_t group_p, const char *group_name,
843 rados_ioctx_t image_p, const char *image_id);
844 CEPH_RBD_API int rbd_group_image_list(
845 rados_ioctx_t group_p, const char *group_name,
846 rbd_group_image_status_t *images,
847 size_t *image_size);
848 CEPH_RBD_API int rbd_image_get_group(rados_ioctx_t image_p,
849 const char *image_name,
850 rbd_group_spec_t *group_spec);
851 CEPH_RBD_API void rbd_group_spec_cleanup(rbd_group_spec_t *group_spec);
852 CEPH_RBD_API void rbd_group_image_status_cleanup(
853 rbd_group_image_status_t *image
854 );
855 CEPH_RBD_API void rbd_group_image_status_list_cleanup(
856 rbd_group_image_status_t *images,
857 size_t len);
858 #ifdef __cplusplus
859 }
860 #endif
861
862 #endif