librbd_sys/
lib.rs

1//! Low level bindings for Ceph's RBD interface.
2//! Please see [Ceph librbd](http://docs.ceph.com/docs/master/rbd/librbdpy/#module-rbd) for more
3//! information. Those are the python docs but the parameters should be the same.
4#![allow(non_camel_case_types)]
5extern crate libc;
6extern crate librados_sys;
7
8use self::libc::{int64_t, size_t, ssize_t, uint8_t, uint64_t};
9use self::librados_sys::rados_ioctx_t;
10
11pub type rbd_snap_t = *mut ::std::os::raw::c_void;
12pub type rbd_image_t = *mut ::std::os::raw::c_void;
13pub type librbd_progress_fn_t =
14    ::std::option::Option<unsafe extern "C" fn(offset: uint64_t,
15                                               total: uint64_t,
16                                               ptr:
17                                                   *mut ::std::os::raw::c_void)
18                              -> ::std::os::raw::c_int>;
19#[repr(C)]
20#[derive(Copy)]
21pub struct rbd_snap_info_t{
22    /// Numeric identifier of the snapshot
23    pub id: uint64_t,
24    /// Size of the image at the time of snapshot (in bytes)
25    pub size: uint64_t,
26    /// Name of the snapshot
27    pub name: *const ::std::os::raw::c_char,
28}
29impl ::std::clone::Clone for rbd_snap_info_t {
30    fn clone(&self) -> Self { *self }
31}
32impl ::std::default::Default for rbd_snap_info_t {
33    fn default() -> Self { unsafe { ::std::mem::zeroed() } }
34}
35
36#[repr(C)]
37#[derive(Copy)]
38pub struct rbd_image_info_t {
39    ///  The size of the image in bytes
40    pub size: uint64_t,
41    /// The size of each object that comprises the image
42    pub obj_size: uint64_t,
43    /// The number of objects in the image
44    pub num_objs: uint64_t,
45    /// log_2(object_size)
46    pub order: ::std::os::raw::c_int,
47    /// The prefix of the RADOS objects used to store the image
48    pub block_name_prefix: [::std::os::raw::c_char; 24usize],
49    /// deprecated
50    pub parent_pool: int64_t,
51    /// deprecated
52    pub parent_name: [::std::os::raw::c_char; 96usize],
53}
54impl ::std::clone::Clone for rbd_image_info_t {
55    fn clone(&self) -> Self { *self }
56}
57impl ::std::default::Default for rbd_image_info_t {
58    fn default() -> Self { unsafe { ::std::mem::zeroed() } }
59}
60pub type rbd_completion_t = *mut ::std::os::raw::c_void;
61pub type rbd_callback_t =
62    ::std::option::Option<unsafe extern "C" fn(cb: rbd_completion_t,
63                                               arg:
64                                                   *mut ::std::os::raw::c_void)>;
65#[link(name = "rbd")]
66extern "C" {
67    /// Get the version number of the librbd C library.
68    pub fn rbd_version(major: *mut ::std::os::raw::c_int,
69                       minor: *mut ::std::os::raw::c_int,
70                       extra: *mut ::std::os::raw::c_int);
71    /// List image names.
72    pub fn rbd_list(io: rados_ioctx_t, names: *mut ::std::os::raw::c_char,
73                    size: *mut size_t) -> ::std::os::raw::c_int;
74    pub fn rbd_create(io: rados_ioctx_t, name: *const ::std::os::raw::c_char,
75                      size: uint64_t, order: *mut ::std::os::raw::c_int)
76     -> ::std::os::raw::c_int;
77    pub fn rbd_create2(io: rados_ioctx_t, name: *const ::std::os::raw::c_char,
78                       size: uint64_t, features: uint64_t,
79                       order: *mut ::std::os::raw::c_int)
80     -> ::std::os::raw::c_int;
81
82    /// create new rbd image
83    ///
84    /// The stripe_unit must be a factor of the object size (1 << order).
85    /// The stripe_count can be one (no intra-object striping) or greater
86    /// than one.  The RBD_FEATURE_STRIPINGV2 must be specified if the
87    /// stripe_unit != the object size and the stripe_count is != 1.
88    ///
89    /// # Arguments
90    ///  * `io` ioctx
91    ///  * `name` image name
92    ///  * `size` image size in bytes
93    ///  * `features` initial feature bits
94    ///  * `order` object/block size, as a power of two (object size == 1 << order)
95    ///  * `stripe_unit` stripe unit size, in bytes.
96    ///  * `stripe_count` number of objects to stripe over before looping
97    /// @return 0 on success, or negative error code
98    pub fn rbd_create3(io: rados_ioctx_t, name: *const ::std::os::raw::c_char,
99                       size: uint64_t, features: uint64_t,
100                       order: *mut ::std::os::raw::c_int,
101                       stripe_unit: uint64_t, stripe_count: uint64_t)
102     -> ::std::os::raw::c_int;
103    /// Clone a parent rbd snapshot into a COW sparse child.
104    pub fn rbd_clone(p_ioctx: rados_ioctx_t,
105                     p_name: *const ::std::os::raw::c_char,
106                     p_snapname: *const ::std::os::raw::c_char,
107                     c_ioctx: rados_ioctx_t,
108                     c_name: *const ::std::os::raw::c_char,
109                     features: uint64_t, c_order: *mut ::std::os::raw::c_int)
110     -> ::std::os::raw::c_int;
111    /// Clone a parent rbd snapshot into a COW sparse child.
112    pub fn rbd_clone2(p_ioctx: rados_ioctx_t,
113                      p_name: *const ::std::os::raw::c_char,
114                      p_snapname: *const ::std::os::raw::c_char,
115                      c_ioctx: rados_ioctx_t,
116                      c_name: *const ::std::os::raw::c_char,
117                      features: uint64_t, c_order: *mut ::std::os::raw::c_int,
118                      stripe_unit: uint64_t,
119                      stripe_count: ::std::os::raw::c_int)
120     -> ::std::os::raw::c_int;
121    /// Delete an RBD image. This may take a long time, since it does not return until every
122    /// object that comprises the image has been deleted. Note that all snapshots must be deleted
123    /// before the image can be removed.
124    pub fn rbd_remove(io: rados_ioctx_t, name: *const ::std::os::raw::c_char)
125     -> ::std::os::raw::c_int;
126    pub fn rbd_remove_with_progress(io: rados_ioctx_t,
127                                    name: *const ::std::os::raw::c_char,
128                                    cb: librbd_progress_fn_t,
129                                    cbdata: *mut ::std::os::raw::c_void)
130     -> ::std::os::raw::c_int;
131    /// Rename an RBD image.
132    pub fn rbd_rename(src_io_ctx: rados_ioctx_t,
133                      srcname: *const ::std::os::raw::c_char,
134                      destname: *const ::std::os::raw::c_char)
135     -> ::std::os::raw::c_int;
136    pub fn rbd_open(io: rados_ioctx_t, name: *const ::std::os::raw::c_char,
137                    image: *mut rbd_image_t,
138                    snap_name: *const ::std::os::raw::c_char)
139     -> ::std::os::raw::c_int;
140
141    /// Open an image in read-only mode.
142    ///
143    /// This is intended for use by clients that cannot write to a block
144    /// device due to cephx restrictions. There will be no watch
145    /// established on the header object, since a watch is a write. This
146    /// means the metadata reported about this image (parents, snapshots,
147    /// size, etc.) may become stale. This should not be used for
148    /// long-running operations, unless you can be sure that one of these
149    /// properties changing is safe.
150    ///
151    /// Attempting to write to a read-only image will return -EROFS.
152    ///
153    /// # Arguments
154    ///  * `io` ioctx to determine the pool the image is in
155    ///  * `name` image name
156    ///  * `image` where to store newly opened image handle
157    ///  * `snap_name` name of snapshot to open at, or NULL for no snapshot
158    /// @returns 0 on success, negative error code on failure
159    pub fn rbd_open_read_only(io: rados_ioctx_t,
160                              name: *const ::std::os::raw::c_char,
161                              image: *mut rbd_image_t,
162                              snap_name: *const ::std::os::raw::c_char)
163     -> ::std::os::raw::c_int;
164    pub fn rbd_close(image: rbd_image_t) -> ::std::os::raw::c_int;
165
166    /// Change the size of the image.
167    pub fn rbd_resize(image: rbd_image_t, size: uint64_t)
168     -> ::std::os::raw::c_int;
169    pub fn rbd_resize_with_progress(image: rbd_image_t, size: uint64_t,
170                                    cb: librbd_progress_fn_t,
171                                    cbdata: *mut ::std::os::raw::c_void)
172     -> ::std::os::raw::c_int;
173    /// Get information about the image. Currently parent pool and parent name are always -1 and ‘’.
174    pub fn rbd_stat(image: rbd_image_t, info: *mut rbd_image_info_t,
175                    infosize: size_t) -> ::std::os::raw::c_int;
176    pub fn rbd_get_old_format(image: rbd_image_t, old: *mut uint8_t)
177     -> ::std::os::raw::c_int;
178    pub fn rbd_get_size(image: rbd_image_t, size: *mut uint64_t)
179     -> ::std::os::raw::c_int;
180    pub fn rbd_get_features(image: rbd_image_t, features: *mut uint64_t)
181     -> ::std::os::raw::c_int;
182    pub fn rbd_get_stripe_unit(image: rbd_image_t, stripe_unit: *mut uint64_t)
183     -> ::std::os::raw::c_int;
184    pub fn rbd_get_stripe_count(image: rbd_image_t,
185                                stripe_count: *mut uint64_t)
186     -> ::std::os::raw::c_int;
187    pub fn rbd_get_overlap(image: rbd_image_t, overlap: *mut uint64_t)
188     -> ::std::os::raw::c_int;
189    pub fn rbd_get_parent_info(image: rbd_image_t,
190                               parent_poolname: *mut ::std::os::raw::c_char,
191                               ppoolnamelen: size_t,
192                               parent_name: *mut ::std::os::raw::c_char,
193                               pnamelen: size_t,
194                               parent_snapname: *mut ::std::os::raw::c_char,
195                               psnapnamelen: size_t) -> ::std::os::raw::c_int;
196    pub fn rbd_copy(image: rbd_image_t, dest_io_ctx: rados_ioctx_t,
197                    destname: *const ::std::os::raw::c_char)
198     -> ::std::os::raw::c_int;
199    pub fn rbd_copy2(src: rbd_image_t, dest: rbd_image_t)
200     -> ::std::os::raw::c_int;
201    pub fn rbd_copy_with_progress(image: rbd_image_t, dest_p: rados_ioctx_t,
202                                  destname: *const ::std::os::raw::c_char,
203                                  cb: librbd_progress_fn_t,
204                                  cbdata: *mut ::std::os::raw::c_void)
205     -> ::std::os::raw::c_int;
206    pub fn rbd_copy_with_progress2(src: rbd_image_t, dest: rbd_image_t,
207                                   cb: librbd_progress_fn_t,
208                                   cbdata: *mut ::std::os::raw::c_void)
209     -> ::std::os::raw::c_int;
210    pub fn rbd_snap_list(image: rbd_image_t, snaps: *mut rbd_snap_info_t,
211                         max_snaps: *mut ::std::os::raw::c_int)
212     -> ::std::os::raw::c_int;
213    pub fn rbd_snap_list_end(snaps: *mut rbd_snap_info_t);
214    pub fn rbd_snap_create(image: rbd_image_t,
215                           snapname: *const ::std::os::raw::c_char)
216     -> ::std::os::raw::c_int;
217    pub fn rbd_snap_remove(image: rbd_image_t,
218                           snapname: *const ::std::os::raw::c_char)
219     -> ::std::os::raw::c_int;
220    pub fn rbd_snap_rollback(image: rbd_image_t,
221                             snapname: *const ::std::os::raw::c_char)
222     -> ::std::os::raw::c_int;
223    pub fn rbd_snap_rollback_with_progress(image: rbd_image_t,
224                                           snapname:
225                                               *const ::std::os::raw::c_char,
226                                           cb: librbd_progress_fn_t,
227                                           cbdata:
228                                               *mut ::std::os::raw::c_void)
229     -> ::std::os::raw::c_int;
230
231    /// Prevent a snapshot from being deleted until it is unprotected.
232    pub fn rbd_snap_protect(image: rbd_image_t,
233                            snap_name: *const ::std::os::raw::c_char)
234     -> ::std::os::raw::c_int;
235
236    /// Allow a snaphshot to be deleted
237    pub fn rbd_snap_unprotect(image: rbd_image_t,
238                              snap_name: *const ::std::os::raw::c_char)
239     -> ::std::os::raw::c_int;
240    /// Determine whether a snapshot is protected.
241    pub fn rbd_snap_is_protected(image: rbd_image_t,
242                                 snap_name: *const ::std::os::raw::c_char,
243                                 is_protected: *mut ::std::os::raw::c_int)
244     -> ::std::os::raw::c_int;
245    pub fn rbd_snap_set(image: rbd_image_t,
246                        snapname: *const ::std::os::raw::c_char)
247     -> ::std::os::raw::c_int;
248    pub fn rbd_flatten(image: rbd_image_t) -> ::std::os::raw::c_int;
249
250    /// List all images that are cloned from the image at the
251    /// snapshot that is set via rbd_snap_set().
252    ///
253    /// This iterates over all pools, so it should be run by a user with
254    /// read access to all of them. pools_len and images_len are filled in
255    /// with the number of bytes put into the pools and images buffers.
256    /// If the provided buffers are too short, the required lengths are
257    /// still filled in, but the data is not and -ERANGE is returned.
258    /// Otherwise, the buffers are filled with the pool and image names
259    /// of the children, with a '\0' after each.
260    /// # Arguments
261    ///  * `image` which image (and implicitly snapshot) to list clones of
262    ///  * `pools` buffer in which to store pool names
263    ///  * `pools_len` number of bytes in pools buffer
264    ///  * `images` buffer in which to store image names
265    ///  * `images_len` number of bytes in images buffer
266    /// @returns number of children on success, negative error code on failure
267    /// @returns -ERANGE if either buffer is too short
268    pub fn rbd_list_children(image: rbd_image_t,
269                             pools: *mut ::std::os::raw::c_char,
270                             pools_len: *mut size_t,
271                             images: *mut ::std::os::raw::c_char,
272                             images_len: *mut size_t) -> ssize_t;
273
274    /// List clients that have locked the image and information about the lock.
275    ///
276    /// The number of bytes required in each buffer is put in the
277    /// corresponding size out parameter. If any of the provided buffers
278    /// are too short, -ERANGE is returned after these sizes are filled in.
279    /// # Arguments
280    ///  * `image` which image (and implicitly snapshot) to list lockers of
281    ///  * `exclusive` where to store whether the lock is exclusive (1) or shared (0)
282    ///  * `tag` where to store the tag associated with the image
283    ///  * `tag_len` number of bytes in tag buffer
284    ///  * `clients` buffer in which locker clients are stored, separated by '\0'
285    ///  * `clients_len` number of bytes in the clients buffer
286    ///  * `cookies` buffer in which locker cookies are stored, separated by '\0'
287    ///  * `cookies_len` number of bytes in the cookies buffer
288    ///  * `addrs` buffer in which locker addresses are stored, separated by '\0'
289    ///  * `addrs_len` number of bytes in the clients buffer
290    /// @returns number of lockers on success, negative error code on failure
291    /// @returns -ERANGE if any of the buffers are too short
292    pub fn rbd_list_lockers(image: rbd_image_t,
293                            exclusive: *mut ::std::os::raw::c_int,
294                            tag: *mut ::std::os::raw::c_char,
295                            tag_len: *mut size_t,
296                            clients: *mut ::std::os::raw::c_char,
297                            clients_len: *mut size_t,
298                            cookies: *mut ::std::os::raw::c_char,
299                            cookies_len: *mut size_t,
300                            addrs: *mut ::std::os::raw::c_char,
301                            addrs_len: *mut size_t) -> ssize_t;
302    /// Take an exclusive lock on the image.
303    /// # Arguments
304    ///  * `image` the image to lock
305    ///  * `cookie` user-defined identifier for this instance of the lock
306    /// @returns 0 on success, negative error code on failure
307    /// @returns -EBUSY if the lock is already held by another (client, cookie) pair
308    /// @returns -EEXIST if the lock is already held by the same (client, cookie) pair
309    pub fn rbd_lock_exclusive(image: rbd_image_t,
310                              cookie: *const ::std::os::raw::c_char)
311     -> ::std::os::raw::c_int;
312
313    /// Take a shared lock on the image.
314    ///
315    /// Other clients may also take a shared lock, as lock as they use the
316    /// same tag.
317    ///
318    /// # Arguments
319    ///  * `image` the image to lock
320    ///  * `cookie` user-defined identifier for this instance of the lock
321    ///  * `tag` user-defined identifier for this shared use of the lock
322    /// @returns 0 on success, negative error code on failure
323    /// @returns -EBUSY if the lock is already held by another (client, cookie) pair
324    /// @returns -EEXIST if the lock is already held by the same (client, cookie) pair
325    pub fn rbd_lock_shared(image: rbd_image_t,
326                           cookie: *const ::std::os::raw::c_char,
327                           tag: *const ::std::os::raw::c_char)
328     -> ::std::os::raw::c_int;
329
330    /// Release a shared or exclusive lock on the image.
331    ///
332    /// # Arguments
333    ///  * `image` the image to unlock
334    ///  * `cookie` user-defined identifier for the instance of the lock
335    /// @returns 0 on success, negative error code on failure
336    /// @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
337    pub fn rbd_unlock(image: rbd_image_t,
338                      cookie: *const ::std::os::raw::c_char)
339     -> ::std::os::raw::c_int;
340
341    /// Release a shared or exclusive lock that was taken by the specified client.
342    ///
343    /// # Arguments
344    /// * `image` the image to unlock
345    /// * `client` the entity holding the lock (as given by rbd_list_lockers())
346    /// * `cookie` user-defined identifier for the instance of the lock to break
347    ///
348    /// @returns 0 on success, negative error code on failure
349    /// @returns -ENOENT if the lock is not held by the specified (client, cookie) pair
350    pub fn rbd_break_lock(image: rbd_image_t,
351                          client: *const ::std::os::raw::c_char,
352                          cookie: *const ::std::os::raw::c_char)
353     -> ::std::os::raw::c_int;
354    pub fn rbd_read(image: rbd_image_t, ofs: uint64_t, len: size_t,
355                    buf: *mut ::std::os::raw::c_char) -> ssize_t;
356
357    /// iterate read over an image
358    /// Reads each region of the image and calls the callback.  If the
359    /// buffer pointer passed to the callback is NULL, the given extent is
360    /// defined to be zeros (a hole).  Normally the granularity for the
361    /// callback is the image stripe size.
362    /// # Arguments
363    ///  * `image` image to read
364    ///  * `ofs` offset to start from
365    ///  * `len` bytes of source image to cover
366    ///  * `cb` callback for each region
367    /// @returns 0 success, error otherwise
368    pub fn rbd_read_iterate2(image: rbd_image_t, ofs: uint64_t, len: uint64_t,
369                             cb:
370                                 ::std::option::Option<unsafe extern "C" fn(arg1:
371                                                                                uint64_t,
372                                                                            arg2:
373                                                                                size_t,
374                                                                            arg3:
375                                                                                *const ::std::os::raw::c_char,
376                                                                            arg4:
377                                                                                *mut ::std::os::raw::c_void)
378                                                           ->
379                                                               ::std::os::raw::c_int>,
380                             arg: *mut ::std::os::raw::c_void)
381     -> ::std::os::raw::c_int;
382
383    /// get difference between two versions of an image
384    ///
385    /// This will return the differences between two versions of an image
386    /// via a callback, which gets the offset and length and a flag
387    /// indicating whether the extent exists (1), or is known/defined to
388    /// be zeros (a hole, 0).  If the source snapshot name is NULL, we
389    /// interpret that as the beginning of time and return all allocated
390    /// regions of the image.  The end version is whatever is currently
391    /// selected for the image handle (either a snapshot or the writeable
392    /// head).
393    /// # Arguments
394    ///  * `fromsnapname` start snapshot name, or NULL
395    ///  * `ofs` start offset
396    ///  * `len` len in bytes of region to report on
397    ///  * `cb` callback to call for each allocated region
398    ///  * `arg` argument to pass to the callback
399    /// @returns 0 on success, or negative error code on error
400    pub fn rbd_diff_iterate(image: rbd_image_t,
401                            fromsnapname: *const ::std::os::raw::c_char,
402                            ofs: uint64_t, len: uint64_t,
403                            cb:
404                                ::std::option::Option<unsafe extern "C" fn(arg1:
405                                                                               uint64_t,
406                                                                           arg2:
407                                                                               size_t,
408                                                                           arg3:
409                                                                               ::std::os::raw::c_int,
410                                                                           arg4:
411                                                                               *mut ::std::os::raw::c_void)
412                                                          ->
413                                                              ::std::os::raw::c_int>,
414                            arg: *mut ::std::os::raw::c_void)
415     -> ::std::os::raw::c_int;
416    pub fn rbd_write(image: rbd_image_t, ofs: uint64_t, len: size_t,
417                     buf: *const ::std::os::raw::c_char) -> ssize_t;
418    /// Trim the range from the image. It will be logically filled with zeroes.
419    /// # Arguments
420    ///  * `image` the image to trim a range from
421    ///  * `ofs` offset to start from
422    ///  * `len` bytes of image to trim
423    pub fn rbd_discard(image: rbd_image_t, ofs: uint64_t, len: uint64_t)
424     -> ::std::os::raw::c_int;
425    pub fn rbd_aio_write(image: rbd_image_t, off: uint64_t, len: size_t,
426                         buf: *const ::std::os::raw::c_char,
427                         c: rbd_completion_t) -> ::std::os::raw::c_int;
428    pub fn rbd_aio_read(image: rbd_image_t, off: uint64_t, len: size_t,
429                        buf: *mut ::std::os::raw::c_char, c: rbd_completion_t)
430     -> ::std::os::raw::c_int;
431    pub fn rbd_aio_discard(image: rbd_image_t, off: uint64_t, len: uint64_t,
432                           c: rbd_completion_t) -> ::std::os::raw::c_int;
433    pub fn rbd_aio_create_completion(cb_arg: *mut ::std::os::raw::c_void,
434                                     complete_cb: rbd_callback_t,
435                                     c: *mut rbd_completion_t)
436     -> ::std::os::raw::c_int;
437    pub fn rbd_aio_is_complete(c: rbd_completion_t) -> ::std::os::raw::c_int;
438    pub fn rbd_aio_wait_for_complete(c: rbd_completion_t)
439     -> ::std::os::raw::c_int;
440    pub fn rbd_aio_get_return_value(c: rbd_completion_t) -> ssize_t;
441    pub fn rbd_aio_release(c: rbd_completion_t);
442
443    /// Start a flush if caching is enabled. Get a callback when
444    /// the currently pending writes are on disk.
445    /// # Arguments
446    ///  * `image` the image to flush writes to
447    ///  * `c` what to call when flushing is complete
448    /// @returns 0 on success, negative error code on failure
449    pub fn rbd_flush(image: rbd_image_t) -> ::std::os::raw::c_int;
450    pub fn rbd_aio_flush(image: rbd_image_t, c: rbd_completion_t)
451     -> ::std::os::raw::c_int;
452
453    /// Drop any cached data for an image
454    ///
455    /// # Arguments
456    ///  * `image` the image to invalidate cached data for
457    /// @returns 0 on success, negative error code on failure
458    pub fn rbd_invalidate_cache(image: rbd_image_t) -> ::std::os::raw::c_int;
459}