Skip to content

Commit

Permalink
Additional async methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jcsp committed Jun 15, 2021
1 parent 2e600e5 commit 6cdb0e4
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions src/ceph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use nom::number::complete::le_u32;
use nom::IResult;
use serde_json;

use crate::completion::{with_completion, Completion};
use crate::completion::with_completion;
use crate::rados::*;
#[cfg(feature = "rados_striper")]
use crate::rados_striper::*;
Expand All @@ -50,6 +50,8 @@ const CEPH_OSD_TMAP_SET: char = 's';
const CEPH_OSD_TMAP_CREATE: char = 'c';
const CEPH_OSD_TMAP_RM: char = 'r';

const DEFAULT_READ_BYTES: usize = 64 * 1024;

#[derive(Debug, Clone)]
pub enum CephHealth {
Ok,
Expand Down Expand Up @@ -962,6 +964,27 @@ impl IoCtx {
.await
}

/// Async variant of rados_object_append
pub async fn rados_async_object_append(
self: &Arc<Self>,
object_name: &str,
buffer: &[u8],
) -> RadosResult<i32> {
self.ioctx_guard()?;
let obj_name_str = CString::new(object_name)?;

with_completion(self.clone(), |c| unsafe {
rados_aio_append(
self.ioctx,
obj_name_str.as_ptr(),
c,
buffer.as_ptr() as *const ::libc::c_char,
buffer.len(),
)
})
.await
}

/// Async variant of rados_object_write_full
pub async fn rados_async_object_write_full(
self: &Arc<Self>,
Expand Down Expand Up @@ -995,6 +1018,33 @@ impl IoCtx {
.map(|_r| ())
}

/// Async variant of rados_object_read
pub async fn rados_async_object_read(
self: &Arc<Self>,
object_name: &str,
fill_buffer: &mut Vec<u8>,
read_offset: u64,
) -> RadosResult<i32> {
self.ioctx_guard()?;
let obj_name_str = CString::new(object_name)?;

if fill_buffer.capacity() == 0 {
fill_buffer.reserve_exact(DEFAULT_READ_BYTES);
}

with_completion(self.clone(), |c| unsafe {
rados_aio_read(
self.ioctx,
obj_name_str.as_ptr(),
c,
fill_buffer.as_mut_ptr() as *mut c_char,
fill_buffer.capacity(),
read_offset,
)
})
.await
}

/// Efficiently copy a portion of one object to another
/// If the underlying filesystem on the OSD supports it, this will be a
/// copy-on-write clone.
Expand Down Expand Up @@ -1052,7 +1102,7 @@ impl IoCtx {
/// amount of bytes read
/// The io context determines the snapshot to read from, if any was set by
/// rados_ioctx_snap_set_read().
/// Default read size is 64K unless you call Vec::with_capacity(1024*128)
/// Default read size is 64K unless you call Vec::with_capacity
/// with a larger size.
pub fn rados_object_read(
&self,
Expand All @@ -1064,7 +1114,7 @@ impl IoCtx {
let object_name_str = CString::new(object_name)?;
let mut len = fill_buffer.capacity();
if len == 0 {
fill_buffer.reserve_exact(1024 * 64);
fill_buffer.reserve_exact(DEFAULT_READ_BYTES);
len = fill_buffer.capacity();
}

Expand Down

0 comments on commit 6cdb0e4

Please sign in to comment.