Skip to content

Commit

Permalink
Merge pull request #1013 from stlankes/syscall
Browse files Browse the repository at this point in the history
add basic support of a virtual filesystem
  • Loading branch information
mkroening authored Jan 16, 2024
2 parents 0bd634b + 7aa591a commit 45a07d4
Show file tree
Hide file tree
Showing 29 changed files with 3,636 additions and 3,013 deletions.
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.11"
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

0 comments on commit 45a07d4

Please sign in to comment.