Skip to content

Commit 8fa92dd

Browse files
slptylerfanelli
authored andcommitted
virtio/fs: translate raw errors in server.rs
Translate raw errors in server.rs to Linux errnos. This fixes bogus ENOSYS when running on macOS. Signed-off-by: Sergio Lopez <[email protected]>
1 parent 461c752 commit 8fa92dd

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/devices/src/virtio/fs/server.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
1111

1212
use vm_memory::ByteValued;
1313

14+
use super::super::linux_errno::linux_error;
1415
use super::bindings;
1516
use super::descriptor_utils::{Reader, Writer};
1617
use super::filesystem::{
@@ -82,7 +83,7 @@ impl<F: FileSystem + Sync> Server<F> {
8283

8384
if in_header.len > (MAX_BUFFER_SIZE + BUFFER_HEADER_SIZE) {
8485
return reply_error(
85-
io::Error::from_raw_os_error(libc::ENOMEM),
86+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
8687
in_header.unique,
8788
w,
8889
);
@@ -143,7 +144,7 @@ impl<F: FileSystem + Sync> Server<F> {
143144
self.removemapping(in_header, r, w, shm.host_addr, shm.size as u64)
144145
}
145146
_ => reply_error(
146-
io::Error::from_raw_os_error(libc::ENOSYS),
147+
linux_error(io::Error::from_raw_os_error(libc::ENOSYS)),
147148
in_header.unique,
148149
w,
149150
),
@@ -511,7 +512,7 @@ impl<F: FileSystem + Sync> Server<F> {
511512

512513
if size > MAX_BUFFER_SIZE {
513514
return reply_error(
514-
io::Error::from_raw_os_error(libc::ENOMEM),
515+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
515516
in_header.unique,
516517
w,
517518
);
@@ -565,7 +566,7 @@ impl<F: FileSystem + Sync> Server<F> {
565566

566567
if size > MAX_BUFFER_SIZE {
567568
return reply_error(
568-
io::Error::from_raw_os_error(libc::ENOMEM),
569+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
569570
in_header.unique,
570571
w,
571572
);
@@ -713,7 +714,7 @@ impl<F: FileSystem + Sync> Server<F> {
713714

714715
if size > MAX_BUFFER_SIZE {
715716
return reply_error(
716-
io::Error::from_raw_os_error(libc::ENOMEM),
717+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
717718
in_header.unique,
718719
w,
719720
);
@@ -743,7 +744,7 @@ impl<F: FileSystem + Sync> Server<F> {
743744

744745
if size > MAX_BUFFER_SIZE {
745746
return reply_error(
746-
io::Error::from_raw_os_error(libc::ENOMEM),
747+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
747748
in_header.unique,
748749
w,
749750
);
@@ -819,7 +820,7 @@ impl<F: FileSystem + Sync> Server<F> {
819820
if major < KERNEL_VERSION {
820821
error!("Unsupported fuse protocol version: {}.{}", major, minor);
821822
return reply_error(
822-
io::Error::from_raw_os_error(libc::EPROTO),
823+
linux_error(io::Error::from_raw_os_error(libc::EPROTO)),
823824
in_header.unique,
824825
w,
825826
);
@@ -842,7 +843,7 @@ impl<F: FileSystem + Sync> Server<F> {
842843
major, minor
843844
);
844845
return reply_error(
845-
io::Error::from_raw_os_error(libc::EPROTO),
846+
linux_error(io::Error::from_raw_os_error(libc::EPROTO)),
846847
in_header.unique,
847848
w,
848849
);
@@ -929,7 +930,7 @@ impl<F: FileSystem + Sync> Server<F> {
929930

930931
if size > MAX_BUFFER_SIZE {
931932
return reply_error(
932-
io::Error::from_raw_os_error(libc::ENOMEM),
933+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
933934
in_header.unique,
934935
w,
935936
);
@@ -938,7 +939,7 @@ impl<F: FileSystem + Sync> Server<F> {
938939
let available_bytes = w.available_bytes();
939940
if available_bytes < size as usize {
940941
return reply_error(
941-
io::Error::from_raw_os_error(libc::ENOMEM),
942+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
942943
in_header.unique,
943944
w,
944945
);
@@ -1187,14 +1188,14 @@ impl<F: FileSystem + Sync> Server<F> {
11871188
if let Some(size) = (count as usize).checked_mul(size_of::<ForgetOne>()) {
11881189
if size > MAX_BUFFER_SIZE as usize {
11891190
return reply_error(
1190-
io::Error::from_raw_os_error(libc::ENOMEM),
1191+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
11911192
in_header.unique,
11921193
w,
11931194
);
11941195
}
11951196
} else {
11961197
return reply_error(
1197-
io::Error::from_raw_os_error(libc::EOVERFLOW),
1198+
linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)),
11981199
in_header.unique,
11991200
w,
12001201
);
@@ -1338,14 +1339,14 @@ impl<F: FileSystem + Sync> Server<F> {
13381339
if let Some(size) = (count as usize).checked_mul(size_of::<RemovemappingOne>()) {
13391340
if size > MAX_BUFFER_SIZE as usize {
13401341
return reply_error(
1341-
io::Error::from_raw_os_error(libc::ENOMEM),
1342+
linux_error(io::Error::from_raw_os_error(libc::ENOMEM)),
13421343
in_header.unique,
13431344
w,
13441345
);
13451346
}
13461347
} else {
13471348
return reply_error(
1348-
io::Error::from_raw_os_error(libc::EOVERFLOW),
1349+
linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)),
13491350
in_header.unique,
13501351
w,
13511352
);
@@ -1433,24 +1434,24 @@ fn add_dirent(
14331434
entry: Option<Entry>,
14341435
) -> io::Result<usize> {
14351436
if d.name.len() > u32::MAX as usize {
1436-
return Err(io::Error::from_raw_os_error(libc::EOVERFLOW));
1437+
return Err(linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)));
14371438
}
14381439

14391440
let dirent_len = size_of::<Dirent>()
14401441
.checked_add(d.name.len())
1441-
.ok_or_else(|| io::Error::from_raw_os_error(libc::EOVERFLOW))?;
1442+
.ok_or_else(|| linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)))?;
14421443

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

14501451
let total_len = if entry.is_some() {
14511452
padded_dirent_len
14521453
.checked_add(size_of::<EntryOut>())
1453-
.ok_or_else(|| io::Error::from_raw_os_error(libc::EOVERFLOW))?
1454+
.ok_or_else(|| linux_error(io::Error::from_raw_os_error(libc::EOVERFLOW)))?
14541455
} else {
14551456
padded_dirent_len
14561457
};

src/devices/src/virtio/linux_errno.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ pub fn linux_errno_raw(errno: i32) -> i32 {
167167
libc::EIDRM => LINUX_EIDRM,
168168
libc::ENOMSG => LINUX_ENOMSG,
169169
libc::EILSEQ => LINUX_EILSEQ,
170+
#[cfg(target_os = "macos")]
170171
libc::ENOATTR => LINUX_ENODATA,
171172
libc::EBADMSG => LINUX_EBADMSG,
172173
libc::EMULTIHOP => LINUX_EMULTIHOP,

src/devices/src/virtio/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub mod file_traits;
2525
pub mod fs;
2626
#[cfg(feature = "gpu")]
2727
pub mod gpu;
28-
#[cfg(target_os = "macos")]
2928
pub mod linux_errno;
3029
mod mmio;
3130
#[cfg(feature = "net")]

0 commit comments

Comments
 (0)