Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio/fs: translate raw errors in server.rs #198

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions src/devices/src/virtio/fs/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::sync::atomic::{AtomicU64, Ordering};

use vm_memory::ByteValued;

use super::super::linux_errno::linux_error;
use super::bindings;
use super::descriptor_utils::{Reader, Writer};
use super::filesystem::{
Expand Down Expand Up @@ -82,7 +83,7 @@ impl<F: FileSystem + Sync> Server<F> {

if in_header.len > (MAX_BUFFER_SIZE + BUFFER_HEADER_SIZE) {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -143,7 +144,7 @@ impl<F: FileSystem + Sync> Server<F> {
self.removemapping(in_header, r, w, shm.host_addr, shm.size as u64)
}
_ => reply_error(
io::Error::from_raw_os_error(libc::ENOSYS),
linux_error(io::Error::from_raw_os_error(libc::ENOSYS)),
in_header.unique,
w,
),
Expand Down Expand Up @@ -511,7 +512,7 @@ impl<F: FileSystem + Sync> Server<F> {

if size > MAX_BUFFER_SIZE {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -565,7 +566,7 @@ impl<F: FileSystem + Sync> Server<F> {

if size > MAX_BUFFER_SIZE {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -713,7 +714,7 @@ impl<F: FileSystem + Sync> Server<F> {

if size > MAX_BUFFER_SIZE {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -743,7 +744,7 @@ impl<F: FileSystem + Sync> Server<F> {

if size > MAX_BUFFER_SIZE {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -819,7 +820,7 @@ impl<F: FileSystem + Sync> Server<F> {
if major < KERNEL_VERSION {
error!("Unsupported fuse protocol version: {}.{}", major, minor);
return reply_error(
io::Error::from_raw_os_error(libc::EPROTO),
linux_error(io::Error::from_raw_os_error(libc::EPROTO)),
in_header.unique,
w,
);
Expand All @@ -842,7 +843,7 @@ impl<F: FileSystem + Sync> Server<F> {
major, minor
);
return reply_error(
io::Error::from_raw_os_error(libc::EPROTO),
linux_error(io::Error::from_raw_os_error(libc::EPROTO)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -929,7 +930,7 @@ impl<F: FileSystem + Sync> Server<F> {

if size > MAX_BUFFER_SIZE {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
Expand All @@ -938,7 +939,7 @@ impl<F: FileSystem + Sync> Server<F> {
let available_bytes = w.available_bytes();
if available_bytes < size as usize {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -1187,14 +1188,14 @@ impl<F: FileSystem + Sync> Server<F> {
if let Some(size) = (count as usize).checked_mul(size_of::<ForgetOne>()) {
if size > MAX_BUFFER_SIZE as usize {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
}
} else {
return reply_error(
io::Error::from_raw_os_error(libc::EOVERFLOW),
linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -1338,14 +1339,14 @@ impl<F: FileSystem + Sync> Server<F> {
if let Some(size) = (count as usize).checked_mul(size_of::<RemovemappingOne>()) {
if size > MAX_BUFFER_SIZE as usize {
return reply_error(
io::Error::from_raw_os_error(libc::ENOMEM),
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
in_header.unique,
w,
);
}
} else {
return reply_error(
io::Error::from_raw_os_error(libc::EOVERFLOW),
linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)),
in_header.unique,
w,
);
Expand Down Expand Up @@ -1433,24 +1434,24 @@ fn add_dirent(
entry: Option<Entry>,
) -> io::Result<usize> {
if d.name.len() > u32::MAX as usize {
return Err(io::Error::from_raw_os_error(libc::EOVERFLOW));
return Err(linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)));
}

let dirent_len = size_of::<Dirent>()
.checked_add(d.name.len())
.ok_or_else(|| io::Error::from_raw_os_error(libc::EOVERFLOW))?;
.ok_or_else(|| linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)))?;

// Directory entries must be padded to 8-byte alignment. If adding 7 causes
// an overflow then this dirent cannot be properly padded.
let padded_dirent_len = dirent_len
.checked_add(7)
.map(|l| l & !7)
.ok_or_else(|| io::Error::from_raw_os_error(libc::EOVERFLOW))?;
.ok_or_else(|| linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)))?;

let total_len = if entry.is_some() {
padded_dirent_len
.checked_add(size_of::<EntryOut>())
.ok_or_else(|| io::Error::from_raw_os_error(libc::EOVERFLOW))?
.ok_or_else(|| linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)))?
} else {
padded_dirent_len
};
Expand Down
1 change: 1 addition & 0 deletions src/devices/src/virtio/linux_errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub fn linux_errno_raw(errno: i32) -> i32 {
libc::EIDRM => LINUX_EIDRM,
libc::ENOMSG => LINUX_ENOMSG,
libc::EILSEQ => LINUX_EILSEQ,
#[cfg(target_os = "macos")]
libc::ENOATTR => LINUX_ENODATA,
libc::EBADMSG => LINUX_EBADMSG,
libc::EMULTIHOP => LINUX_EMULTIHOP,
Expand Down
1 change: 0 additions & 1 deletion src/devices/src/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod file_traits;
pub mod fs;
#[cfg(feature = "gpu")]
pub mod gpu;
#[cfg(target_os = "macos")]
pub mod linux_errno;
mod mmio;
#[cfg(feature = "net")]
Expand Down
Loading