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

add basic support of a virtual filesystem #1013

Merged
merged 32 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e1b85e3
move virtual filesystem to the directory vfs
stlankes Dec 25, 2023
5ee8bd0
rename feature fs to fuse
stlankes Dec 25, 2023
ba9f92c
revise filesystem interface
stlankes Jan 2, 2024
fa56ef3
remove some clippy warnings
stlankes Jan 2, 2024
0ae2f2e
remove platform independent part to the syscall interface
stlankes Jan 2, 2024
30d52b1
revise visibility of the modules
stlankes Jan 2, 2024
e0f25fb
add basic support to create, read and write files
stlankes Jan 3, 2024
3e2061d
remove clippy warnings
stlankes Jan 3, 2024
0f32627
add tracing of closing a file descriptor
stlankes Jan 3, 2024
ac6a4bc
fix bug in accept
stlankes Jan 3, 2024
db0e097
remove clippy warnings
stlankes Jan 3, 2024
b838a7f
revise socket interface
stlankes Jan 3, 2024
fd908eb
remove clippy warnings
stlankes Jan 3, 2024
7b886b1
revise interface to enable the nonblocking mode
stlankes Jan 3, 2024
2bc8a33
add bitflag CreationMode to specify the mode of new files
stlankes Jan 4, 2024
aeb5016
add option to specify the mount point of uhyve's filesystem
stlankes Jan 4, 2024
21b9688
return an error number if unwrapping of CreationOption fails
stlankes Jan 4, 2024
baa86cf
create on demand the object interface to the ramdisk
stlankes Jan 4, 2024
631d0db
rename CreationMode to AccessPermission
stlankes Jan 4, 2024
b6869de
add basic support of file attributes
stlankes Jan 4, 2024
a44a373
move all functions to realize system calls to the directory syscalls
stlankes Jan 4, 2024
1eaab6c
add check if udp and/or tcp support is activated
stlankes Jan 4, 2024
3eab876
revise IO interface
stlankes Jan 5, 2024
c79af48
add constants to specifiy the file type
stlankes Jan 6, 2024
f66b3cb
add option to support file metadata
stlankes Jan 6, 2024
f2d12f6
fix bug in the reconstruction of the file path
stlankes Jan 6, 2024
6342e97
extend AccessPermission to determine the file type
stlankes Jan 6, 2024
53e09bf
add comments and extend support of meta information
stlankes Jan 6, 2024
c91f514
extend Metadata to determine last access and modification time
stlankes Jan 6, 2024
d1d5b75
allows the creation of a file at any position of the fs
stlankes Jan 6, 2024
f4205b8
replace sys_readdir by sys_getdents64
stlankes Jan 9, 2024
7aa591a
remove obsolete clone operations
stlankes Jan 15, 2024
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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ name = "measure_startup_time"
harness = false

[features]
default = ["pci", "pci-ids", "acpi", "fsgsbase", "smp", "tcp", "dhcpv4", "fs"]
default = ["pci", "pci-ids", "acpi", "fsgsbase", "smp", "tcp", "dhcpv4", "fuse"]
acpi = []
dhcpv4 = [
"smoltcp",
"smoltcp/proto-dhcpv4",
"smoltcp/socket-dhcpv4",
]
fs = ["pci"]
fs = ["fuse"]
fuse = ["pci"]
fsgsbase = []
gem-net = ["tcp"]
newlib = []
Expand Down Expand Up @@ -92,6 +93,7 @@ take-static = "0.1"
talc = { version = "4" }
time = { version = "0.3", default-features = false }
zerocopy = { version = "0.7", features = ["derive"] }
build-time = "0.1.3"

[dependencies.smoltcp]
version = "0.10"
Expand Down
12 changes: 6 additions & 6 deletions src/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A module containing hermit-rs driver, hermit-rs driver trait and driver specific errors.

#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
pub mod fs;
#[cfg(not(feature = "pci"))]
pub mod mmio;
Expand All @@ -10,7 +10,7 @@ pub mod net;
pub mod pci;
#[cfg(any(
all(any(feature = "tcp", feature = "udp"), not(feature = "rtl8139")),
feature = "fs"
feature = "fuse"
))]
pub mod virtio;

Expand All @@ -26,15 +26,15 @@ pub mod error {
use crate::drivers::net::rtl8139::RTL8139Error;
#[cfg(any(
all(any(feature = "tcp", feature = "udp"), not(feature = "rtl8139")),
feature = "fs"
feature = "fuse"
))]
use crate::drivers::virtio::error::VirtioError;

#[derive(Debug)]
pub enum DriverError {
#[cfg(any(
all(any(feature = "tcp", feature = "udp"), not(feature = "rtl8139")),
feature = "fs"
feature = "fuse"
))]
InitVirtioDevFail(VirtioError),
#[cfg(feature = "rtl8139")]
Expand All @@ -45,7 +45,7 @@ pub mod error {

#[cfg(any(
all(any(feature = "tcp", feature = "udp"), not(feature = "rtl8139")),
feature = "fs"
feature = "fuse"
))]
impl From<VirtioError> for DriverError {
fn from(err: VirtioError) -> Self {
Expand Down Expand Up @@ -73,7 +73,7 @@ pub mod error {
match *self {
#[cfg(any(
all(any(feature = "tcp", feature = "udp"), not(feature = "rtl8139")),
feature = "fs"
feature = "fuse"
))]
DriverError::InitVirtioDevFail(ref err) => {
write!(f, "Virtio driver failed: {err:?}")
Expand Down
18 changes: 9 additions & 9 deletions src/drivers/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::fmt;

use bitflags::bitflags;
use hermit_sync::without_interrupts;
#[cfg(any(feature = "tcp", feature = "udp", feature = "fs"))]
#[cfg(any(feature = "tcp", feature = "udp", feature = "fuse"))]
use hermit_sync::InterruptTicketMutex;
use pci_types::{
Bar, ConfigRegionAccess, DeviceId, EndpointHeader, InterruptLine, InterruptPin, PciAddress,
Expand All @@ -14,20 +14,20 @@ use pci_types::{

use crate::arch::mm::{PhysAddr, VirtAddr};
use crate::arch::pci::PciConfigRegion;
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
use crate::drivers::fs::virtio_fs::VirtioFsDriver;
#[cfg(feature = "rtl8139")]
use crate::drivers::net::rtl8139::{self, RTL8139Driver};
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
use crate::drivers::net::virtio_net::VirtioNetDriver;
#[cfg(any(
all(any(feature = "tcp", feature = "udp"), not(feature = "rtl8139")),
feature = "fs"
feature = "fuse"
))]
use crate::drivers::virtio::transport::pci as pci_virtio;
#[cfg(any(
all(any(feature = "tcp", feature = "udp"), not(feature = "rtl8139")),
feature = "fs"
feature = "fuse"
))]
use crate::drivers::virtio::transport::pci::VirtioDriver;

Expand Down Expand Up @@ -466,7 +466,7 @@ pub(crate) fn print_information() {

#[allow(clippy::large_enum_variant)]
pub(crate) enum PciDriver {
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
VirtioFs(InterruptTicketMutex<VirtioFsDriver>),
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
VirtioNet(InterruptTicketMutex<VirtioNetDriver>),
Expand All @@ -493,7 +493,7 @@ impl PciDriver {
}
}

#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
fn get_filesystem_driver(&self) -> Option<&InterruptTicketMutex<VirtioFsDriver>> {
match self {
Self::VirtioFs(drv) => Some(drv),
Expand All @@ -519,7 +519,7 @@ pub(crate) fn get_network_driver() -> Option<&'static InterruptTicketMutex<RTL81
unsafe { PCI_DRIVERS.iter().find_map(|drv| drv.get_network_driver()) }
}

#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
pub(crate) fn get_filesystem_driver() -> Option<&'static InterruptTicketMutex<VirtioFsDriver>> {
unsafe {
PCI_DRIVERS
Expand All @@ -544,14 +544,14 @@ pub(crate) fn init_drivers() {

#[cfg(any(
all(any(feature = "tcp", feature = "udp"), not(feature = "rtl8139")),
feature = "fs"
feature = "fuse"
))]
match pci_virtio::init_device(adapter) {
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
Ok(VirtioDriver::Network(drv)) => {
register_driver(PciDriver::VirtioNet(InterruptTicketMutex::new(drv)))
}
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
Ok(VirtioDriver::FileSystem(drv)) => {
register_driver(PciDriver::VirtioFs(InterruptTicketMutex::new(drv)))
}
Expand Down
6 changes: 3 additions & 3 deletions src/drivers/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod virtqueue;
pub mod error {
use core::fmt;

#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
pub use crate::drivers::fs::virtio_fs::error::VirtioFsError;
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
pub use crate::drivers::net::virtio_net::error::VirtioNetError;
Expand All @@ -23,7 +23,7 @@ pub mod error {
DevNotSupported(u16),
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
NetDriver(VirtioNetError),
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
FsDriver(VirtioFsError),
#[cfg(not(feature = "pci"))]
Unknown,
Expand Down Expand Up @@ -56,7 +56,7 @@ pub mod error {
VirtioNetError::ProcessOngoing => write!(f, "Virtio network performed an unsuitable operation upon an ongoging transfer."),
VirtioNetError::Unknown => write!(f, "Virtio network driver failed due unknown reason!"),
},
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
VirtioError::FsDriver(fs_error) => match fs_error {
VirtioFsError::NoDevCfg(id) => write!(f, "Virtio filesystem driver failed, for device {id:x}, due to a missing or malformed device config!"),
VirtioFsError::NoComCfg(id) => write!(f, "Virtio filesystem driver failed, for device {id:x}, due to a missing or malformed common config!"),
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::arch::memory_barrier;
use crate::arch::mm::PhysAddr;
use crate::arch::pci::PciConfigRegion;
use crate::drivers::error::DriverError;
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
use crate::drivers::fs::virtio_fs::VirtioFsDriver;
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
use crate::drivers::net::network_irqhandler;
Expand Down Expand Up @@ -1267,7 +1267,7 @@ pub(crate) fn init_device(
Err(DriverError::InitVirtioDevFail(virtio_error))
}
},
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
DevId::VIRTIO_DEV_ID_FS => {
// TODO: check subclass
// TODO: proper error handling on driver creation fail
Expand Down Expand Up @@ -1311,7 +1311,7 @@ pub(crate) fn init_device(

Ok(drv)
}
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
VirtioDriver::FileSystem(_) => Ok(drv),
}
}
Expand All @@ -1322,6 +1322,6 @@ pub(crate) fn init_device(
pub(crate) enum VirtioDriver {
#[cfg(all(not(feature = "rtl8139"), any(feature = "tcp", feature = "udp")))]
Network(VirtioNetDriver),
#[cfg(feature = "fs")]
#[cfg(feature = "fuse")]
FileSystem(VirtioFsDriver),
}
4 changes: 4 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl Default for Cli {
let gateway = expect_arg(words.next(), word.as_str());
env_vars.insert(String::from("HERMIT_GATEWAY"), gateway);
}
"-mount" => {
let gateway = expect_arg(words.next(), word.as_str());
env_vars.insert(String::from("UHYVE_MOUNT"), gateway);
}
"--" => args.extend(&mut words),
_ if image_path.is_none() => image_path = Some(word),
word => panic!(
Expand Down
13 changes: 7 additions & 6 deletions src/executor/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::drivers::net::NetworkDriver;
use crate::drivers::pci::get_network_driver;
use crate::executor::device::HermitNet;
use crate::executor::{spawn, TaskNotify};
use crate::fd::IoError;
use crate::scheduler::PerCoreSchedulerExt;

pub(crate) enum NetworkState<'a> {
Expand Down Expand Up @@ -248,9 +249,9 @@ fn network_poll(timestamp: Instant) {
}

/// Blocks the current thread on `f`, running the executor when idling.
pub(crate) fn block_on<F, T>(future: F, timeout: Option<Duration>) -> Result<T, i32>
pub(crate) fn block_on<F, T>(future: F, timeout: Option<Duration>) -> Result<T, IoError>
where
F: Future<Output = Result<T, i32>>,
F: Future<Output = Result<T, IoError>>,
{
// disable network interrupts
let no_retransmission = {
Expand Down Expand Up @@ -297,7 +298,7 @@ where
// allow network interrupts
get_network_driver().unwrap().lock().set_polling_mode(false);

return Err(-crate::errno::ETIME);
return Err(IoError::ETIME);
}
}

Expand Down Expand Up @@ -327,9 +328,9 @@ where
}

/// Blocks the current thread on `f`, running the executor when idling.
pub(crate) fn poll_on<F, T>(future: F, timeout: Option<Duration>) -> Result<T, i32>
pub(crate) fn poll_on<F, T>(future: F, timeout: Option<Duration>) -> Result<T, IoError>
where
F: Future<Output = Result<T, i32>>,
F: Future<Output = Result<T, IoError>>,
{
// disable network interrupts
let no_retransmission = {
Expand Down Expand Up @@ -372,7 +373,7 @@ where
// allow network interrupts
get_network_driver().unwrap().lock().set_polling_mode(false);

return Err(-crate::errno::ETIME);
return Err(IoError::ETIME);
}
}
}
Expand Down
Loading