Skip to content

Commit 6408b9e

Browse files
authored
Bump crucible and update APIs (#663)
Bump crucible, add read_bytes_uninit
1 parent 3e296a6 commit 6408b9e

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

Cargo.lock

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ oximeter-producer = { git = "https://github.com/oxidecomputer/omicron", branch =
7878
oximeter = { git = "https://github.com/oxidecomputer/omicron", branch = "main" }
7979

8080
# Crucible
81-
crucible = { git = "https://github.com/oxidecomputer/crucible", rev = "1c1574fb721f98f2df1b23e3fd27d83be018882e" }
82-
crucible-client-types = { git = "https://github.com/oxidecomputer/crucible", rev = "1c1574fb721f98f2df1b23e3fd27d83be018882e" }
81+
crucible = { git = "https://github.com/oxidecomputer/crucible", rev = "952c7d60d22be5198b892bec8d92f4291b9160c2" }
82+
crucible-client-types = { git = "https://github.com/oxidecomputer/crucible", rev = "952c7d60d22be5198b892bec8d92f4291b9160c2" }
8383

8484
# External dependencies
8585
anyhow = "1.0"

lib/propolis/src/block/crucible.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,24 @@ async fn process_request(
391391
// to crucible
392392
let maps =
393393
req.mappings(mem).ok_or_else(|| Error::BadGuestRegion)?;
394-
let mut vec: Vec<u8> = vec![0; len];
394+
let mut data = crucible::BytesMut::with_capacity(len);
395395
let mut nread = 0;
396396
for mapping in maps {
397-
nread += mapping
398-
.read_bytes(&mut vec[nread..(nread + mapping.len())])?;
397+
let n = mapping.read_bytes_uninit(
398+
&mut data.spare_capacity_mut()[..mapping.len()],
399+
)?;
400+
// `read_bytes` returns the number of bytes written, so we can
401+
// expand our initialized area by this amount.
402+
unsafe {
403+
data.set_len(data.len() + n);
404+
}
405+
nread += n;
399406
}
400407
if nread != len {
401408
return Err(Error::CopyError(nread, len));
402409
}
403410

404-
let _ = block.write(off_blocks, crucible::Bytes::from(vec)).await?;
411+
let _ = block.write(off_blocks, data).await?;
405412
}
406413
block::Operation::Flush => {
407414
if !skip_flush {

lib/propolis/src/vmm/mem.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::io::{Error, ErrorKind, Result};
88
use std::marker::PhantomData;
9-
use std::mem::{size_of, size_of_val};
9+
use std::mem::{size_of, size_of_val, MaybeUninit};
1010
use std::ops::RangeInclusive;
1111
use std::os::unix::io::{AsRawFd, RawFd};
1212
use std::ptr::{copy_nonoverlapping, NonNull};
@@ -532,6 +532,21 @@ impl<'a> SubMapping<'a> {
532532
Ok(read_len)
533533
}
534534

535+
/// Reads a buffer of bytes from the mapping into an uninitialized region
536+
///
537+
/// If `buf` is larger than the SubMapping, the read will be truncated to
538+
/// length of the SubMapping.
539+
///
540+
/// Returns the number of bytes read.
541+
pub fn read_bytes_uninit(
542+
&self,
543+
buf: &mut [MaybeUninit<u8>],
544+
) -> Result<usize> {
545+
let read_len = usize::min(buf.len(), self.len);
546+
self.read_many(&mut buf[..read_len])?;
547+
Ok(read_len)
548+
}
549+
535550
/// Pread from `file` into the mapping.
536551
pub fn pread(
537552
&self,

0 commit comments

Comments
 (0)