From 80806cbd96f370672dc328872a61cbd5cfa0b79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 3 Dec 2025 14:00:04 +0100 Subject: [PATCH 1/2] style(pci): remove non-trailing comma in `cfg` attributes --- src/drivers/pci.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/drivers/pci.rs b/src/drivers/pci.rs index 1b9f613f2d..32996acb2d 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -25,17 +25,17 @@ use crate::drivers::console::{VirtioConsoleDriver, VirtioUART}; use crate::drivers::fs::virtio_fs::VirtioFsDriver; #[cfg(feature = "rtl8139")] use crate::drivers::net::rtl8139::{self, RTL8139Driver}; -#[cfg(all(not(feature = "rtl8139"), feature = "virtio-net",))] +#[cfg(all(not(feature = "rtl8139"), feature = "virtio-net"))] use crate::drivers::net::virtio::VirtioNetDriver; #[cfg(any( - all(feature = "virtio-net", not(feature = "rtl8139"),), + all(feature = "virtio-net", not(feature = "rtl8139")), feature = "fuse", feature = "vsock", feature = "console", ))] use crate::drivers::virtio::transport::pci as pci_virtio; #[cfg(any( - all(feature = "virtio-net", not(feature = "rtl8139"),), + all(feature = "virtio-net", not(feature = "rtl8139")), feature = "fuse", feature = "vsock", feature = "console", @@ -45,7 +45,7 @@ use crate::drivers::virtio::transport::pci::VirtioDriver; use crate::drivers::vsock::VirtioVsockDriver; #[allow(unused_imports)] use crate::drivers::{Driver, InterruptHandlerQueue}; -#[cfg(any(feature = "rtl8139", feature = "virtio-net",))] +#[cfg(any(feature = "rtl8139", feature = "virtio-net"))] use crate::executor::device::NETWORK_DEVICE; use crate::init_cell::InitCell; @@ -449,7 +449,7 @@ pub(crate) fn get_interrupt_handlers() -> HashMap *crate::executor::device::NETWORK_DEVICE.lock() = Some(drv), #[cfg(feature = "console")] From 1972e98e9f55ce942e792525f932fabda4b46e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 3 Dec 2025 14:04:19 +0100 Subject: [PATCH 2/2] refactor: simplify virtio cfgs --- src/config.rs | 8 +------- src/drivers/mod.rs | 43 +++++-------------------------------------- src/drivers/pci.rs | 21 +++------------------ 3 files changed, 9 insertions(+), 63 deletions(-) diff --git a/src/config.rs b/src/config.rs index d4312984ca..e3c7d47ba3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,13 +5,7 @@ pub const DEFAULT_STACK_SIZE: usize = 0x0001_0000; pub(crate) const USER_STACK_SIZE: usize = 0x0010_0000; #[cfg(any( - all( - not(any( - all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")), - feature = "rtl8139", - )), - feature = "virtio-net", - ), + feature = "virtio-net", feature = "fuse", feature = "vsock", feature = "console", diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs index ea92f08c1f..9615b10e6a 100644 --- a/src/drivers/mod.rs +++ b/src/drivers/mod.rs @@ -10,16 +10,7 @@ pub mod mmio; pub mod net; #[cfg(feature = "pci")] pub mod pci; -#[cfg(any( - all( - not(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci"))), - not(feature = "rtl8139"), - feature = "virtio-net", - ), - feature = "fuse", - feature = "vsock", - feature = "console", -))] +#[cfg(feature = "virtio")] pub mod virtio; #[cfg(feature = "vsock")] pub mod vsock; @@ -38,12 +29,9 @@ pub(crate) type InterruptHandlerQueue = VecDeque; /// passed on to higher layers. pub mod error { #[cfg(any( + feature = "virtio", all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")), feature = "rtl8139", - feature = "virtio-net", - feature = "fuse", - feature = "vsock", - feature = "console", ))] use thiserror::Error; @@ -51,38 +39,17 @@ pub mod error { use crate::drivers::net::gem::GEMError; #[cfg(feature = "rtl8139")] use crate::drivers::net::rtl8139::RTL8139Error; - #[cfg(any( - all( - not(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci"))), - not(feature = "rtl8139"), - feature = "virtio-net", - ), - feature = "fuse", - feature = "vsock", - feature = "console", - ))] + #[cfg(feature = "virtio")] use crate::drivers::virtio::error::VirtioError; #[cfg(any( + feature = "virtio", all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")), feature = "rtl8139", - feature = "virtio-net", - feature = "fuse", - feature = "vsock", - feature = "console", ))] #[derive(Error, Debug)] pub enum DriverError { - #[cfg(any( - all( - not(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci"))), - not(feature = "rtl8139"), - feature = "virtio-net", - ), - feature = "fuse", - feature = "vsock", - feature = "console", - ))] + #[cfg(feature = "virtio")] #[error("Virtio driver failed: {0:?}")] InitVirtioDevFail(#[from] VirtioError), diff --git a/src/drivers/pci.rs b/src/drivers/pci.rs index 32996acb2d..76df1331c1 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -27,19 +27,9 @@ use crate::drivers::fs::virtio_fs::VirtioFsDriver; use crate::drivers::net::rtl8139::{self, RTL8139Driver}; #[cfg(all(not(feature = "rtl8139"), feature = "virtio-net"))] use crate::drivers::net::virtio::VirtioNetDriver; -#[cfg(any( - all(feature = "virtio-net", not(feature = "rtl8139")), - feature = "fuse", - feature = "vsock", - feature = "console", -))] +#[cfg(feature = "virtio")] use crate::drivers::virtio::transport::pci as pci_virtio; -#[cfg(any( - all(feature = "virtio-net", not(feature = "rtl8139")), - feature = "fuse", - feature = "vsock", - feature = "console", -))] +#[cfg(feature = "virtio")] use crate::drivers::virtio::transport::pci::VirtioDriver; #[cfg(feature = "vsock")] use crate::drivers::vsock::VirtioVsockDriver; @@ -502,12 +492,7 @@ pub(crate) fn init() { adapter.device_id() ); - #[cfg(any( - all(feature = "virtio-net", not(feature = "rtl8139")), - feature = "fuse", - feature = "vsock", - feature = "console", - ))] + #[cfg(feature = "virtio")] match pci_virtio::init_device(adapter) { #[cfg(all(not(feature = "rtl8139"), feature = "virtio-net"))] Ok(VirtioDriver::Network(drv)) => *crate::executor::device::NETWORK_DEVICE.lock() = Some(drv),