Skip to content

Commit

Permalink
chore: bump vhost version from 0.6.0 to 0.11.0
Browse files Browse the repository at this point in the history
Follow the RUSTSEC-2024-0002 advisor, bump vhost version

Signed-off-by: Yang Kaiyong <yangkaiyong.yky@antgroup.com>
  • Loading branch information
Yang Kaiyong committed Jan 22, 2025
1 parent 387521d commit 5603c65
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 24 deletions.
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ build = "build.rs"
arc-swap = "1.5"
async-trait = { version = "0.1.42", optional = true }
bitflags = "1.1"
dbs-snapshot = { version = "1.5.0", optional = true }
dbs-snapshot = { version = "1.5.2", optional = true }
io-uring = { version = "0.5.8", optional = true }
lazy_static = "1.4"
libc = "0.2.68"
Expand All @@ -33,9 +33,9 @@ tokio-uring = { version = "0.4.0", optional = true }
vmm-sys-util = { version = "0.12.1", optional = true }
vm-memory = { version = "0.16.1", features = ["backend-mmap"] }
virtio-queue = { version = "0.14.0", optional = true }
vhost = { version = "0.6", features = ["vhost-user-slave"], optional = true }
vhost = { version = "0.11.0", features = ["vhost-user","vhost-user-backend"], optional = true }
versionize_derive = { version = "0.1.6", optional = true }
versionize = { version = "0.1.10", optional = true }
versionize = { version = "0.2.0", optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation-sys = { version = ">=0.8", optional = true }
Expand Down Expand Up @@ -66,7 +66,6 @@ virtiofs = ["virtio-queue", "caps", "vmm-sys-util"]
vhost-user-fs = ["virtiofs", "vhost", "caps"]
persist = ["dbs-snapshot", "versionize", "versionize_derive"]
fuse-t = []
async_io = []

[package.metadata.docs.rs]
all-features = true
Expand Down
7 changes: 6 additions & 1 deletion src/abi/fuse_abi_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,12 @@ mod tests {
let buf = [
0x1u8, 0x2u8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5u8, 0x6u8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
];
let forget: &ForgetOne = ForgetOne::from_slice(&buf).unwrap();
let forget = match ForgetOne::from_slice(&buf) {
Some(f) => f,
None => {
panic!("Failed to parse ForgetOne from buffer: {:?}", buf)
}
};

assert_eq!(forget.nodeid, 0x201u64);
assert_eq!(forget.nlookup, 0x605u64);
Expand Down
7 changes: 6 additions & 1 deletion src/abi/fuse_abi_macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,12 @@ mod tests {
let buf = [
0x1u8, 0x2u8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5u8, 0x6u8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
];
let forget: &ForgetOne = ForgetOne::from_slice(&buf).unwrap();
let forget = match ForgetOne::from_slice(&buf) {
Some(f) => f,
None => {
panic!("Failed to parse ForgetOne from buffer: {:?}", buf)
}
};

assert_eq!(forget.nodeid, 0x201u64);
assert_eq!(forget.nlookup, 0x605u64);
Expand Down
4 changes: 2 additions & 2 deletions src/passthrough/file_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ mod tests {
buf: Vec<libc::c_char>,
) -> CFileHandle {
let mut wrapper = CFileHandle::new(handle_bytes);
let fh = wrapper.wrapper.as_mut_fam_struct();
let fh = unsafe { wrapper.wrapper.as_mut_fam_struct() };
fh.handle_type = handle_type;
unsafe {
fh.f_handle
Expand Down Expand Up @@ -401,7 +401,7 @@ mod tests {
fn test_c_file_handle_wrapper() {
let buf = (0..=127).collect::<Vec<libc::c_char>>();
let mut wrapper = generate_c_file_handle(MAX_HANDLE_SIZE, 3, buf.clone());
let fh = wrapper.wrapper.as_mut_fam_struct();
let fh = unsafe { wrapper.wrapper.as_mut_fam_struct() };

assert_eq!(fh.handle_bytes as usize, MAX_HANDLE_SIZE);
assert_eq!(fh.handle_type, 3);
Expand Down
20 changes: 10 additions & 10 deletions src/transport/fs_cache_req_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ mod virtiofs {

#[cfg(feature = "vhost-user-fs")]
use vhost::vhost_user::message::{
VhostUserFSSlaveMsg, VhostUserFSSlaveMsgFlags, VHOST_USER_FS_SLAVE_ENTRIES,
VhostUserFSBackendMsg, VhostUserFSBackendMsgFlags, VHOST_USER_FS_BACKEND_ENTRIES,
};
#[cfg(feature = "vhost-user-fs")]
use vhost::vhost_user::{SlaveFsCacheReq, VhostUserMasterReqHandler};
use vhost::vhost_user::{Backend, VhostUserFrontendReqHandler};

use crate::abi::virtio_fs::RemovemappingOne;
#[cfg(feature = "vhost-user-fs")]
Expand Down Expand Up @@ -54,7 +54,7 @@ mod virtiofs {
}

#[cfg(feature = "vhost-user-fs")]
impl FsCacheReqHandler for SlaveFsCacheReq {
impl FsCacheReqHandler for Backend {
fn map(
&mut self,
foffset: u64,
Expand All @@ -63,31 +63,31 @@ mod virtiofs {
flags: u64,
fd: RawFd,
) -> io::Result<()> {
let mut msg: VhostUserFSSlaveMsg = Default::default();
let mut msg: VhostUserFSBackendMsg = Default::default();
msg.fd_offset[0] = foffset;
msg.cache_offset[0] = moffset;
msg.len[0] = len;
msg.flags[0] = if (flags & SetupmappingFlags::WRITE.bits()) != 0 {
VhostUserFSSlaveMsgFlags::MAP_W | VhostUserFSSlaveMsgFlags::MAP_R
VhostUserFSBackendMsgFlags::MAP_W | VhostUserFSBackendMsgFlags::MAP_R
} else {
VhostUserFSSlaveMsgFlags::MAP_R
VhostUserFSBackendMsgFlags::MAP_R
};

self.fs_slave_map(&msg, &fd)?;
self.fs_backend_map(&msg, &fd)?;

Ok(())
}

fn unmap(&mut self, requests: Vec<RemovemappingOne>) -> io::Result<()> {
for chunk in requests.chunks(VHOST_USER_FS_SLAVE_ENTRIES) {
let mut msg: VhostUserFSSlaveMsg = Default::default();
for chunk in requests.chunks(VHOST_USER_FS_BACKEND_ENTRIES) {
let mut msg: VhostUserFSBackendMsg = Default::default();

for (ind, req) in chunk.iter().enumerate() {
msg.len[ind] = req.len;
msg.cache_offset[ind] = req.moffset;
}

self.fs_slave_unmap(&msg)?;
self.fs_backend_unmap(&msg)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/transport/fusedev/fuse_t_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn fuse_kern_mount(
cmd.arg("-r");
}
cmd.arg(mountpoint);
cmd.exec();
let _ = cmd.exec();
panic!("never arrive here")
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/transport/fusedev/macos_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,14 @@ fn create_disk(mountpoint: &Path, dasession: DASessionRef) -> DADiskRef {
let url =
CFURLCreateWithFileSystemPath(std::ptr::null(), url_str, kCFURLPOSIXPathStyle, 1u8);
let disk = DADiskCreateFromVolumePath(std::ptr::null(), dasession, url);
CFRelease(std::mem::transmute(url_str));
CFRelease(std::mem::transmute(url));
CFRelease(std::mem::transmute::<
*const core_foundation_sys::string::__CFString,
*const libc::c_void,
>(url_str));
CFRelease(std::mem::transmute::<
*const core_foundation_sys::url::__CFURL,
*const libc::c_void,
>(url));
disk
}
}
Expand All @@ -419,7 +425,7 @@ fn fuse_kern_umount(file: File, disk: Option<DADiskRef>) -> Result<()> {
None,
std::ptr::null_mut(),
);
CFRelease(std::mem::transmute(disk));
CFRelease(std::mem::transmute::<DADiskRef, *const libc::c_void>(disk));
}
}
Ok(())
Expand Down
6 changes: 4 additions & 2 deletions src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,27 +797,29 @@ mod tests {
#[test]
fn test_mark_dirty() {
let mut buf1 = vec![0x0u8; 16];
let bitmap1 = AtomicBitmap::new(16, 2);
let bitmap1 = AtomicBitmap::new(16, std::num::NonZero::new(2).unwrap());

assert_eq!(bitmap1.len(), 8);
for i in 0..8 {
assert_eq!(bitmap1.is_bit_set(i), false);
}

let mut buf2 = vec![0x0u8; 16];
let bitmap2 = AtomicBitmap::new(16, 2);
let bitmap2 = AtomicBitmap::new(16, std::num::NonZero::new(2).unwrap());
let mut bufs = VecDeque::new();

unsafe {
bufs.push_back(VolatileSlice::with_bitmap(
buf1.as_mut_ptr(),
buf1.len(),
bitmap1.slice_at(0),
None,
));
bufs.push_back(VolatileSlice::with_bitmap(
buf2.as_mut_ptr(),
buf2.len(),
bitmap2.slice_at(0),
None,
));
}
let mut buffers = IoBuffers {
Expand Down

0 comments on commit 5603c65

Please sign in to comment.