Skip to content

Commit 690f22d

Browse files
committed
refactor: simplify virtio cfgs
1 parent 80806cb commit 690f22d

File tree

3 files changed

+9
-68
lines changed

3 files changed

+9
-68
lines changed

src/config.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@ pub const DEFAULT_STACK_SIZE: usize = 0x0001_0000;
44

55
pub(crate) const USER_STACK_SIZE: usize = 0x0010_0000;
66

7-
#[cfg(any(
8-
all(
9-
not(any(
10-
all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")),
11-
feature = "rtl8139",
12-
)),
13-
feature = "virtio-net",
14-
),
15-
feature = "fuse",
16-
feature = "vsock",
17-
feature = "console",
18-
))]
7+
#[cfg(feature = "virtio")]
198
pub(crate) const VIRTIO_MAX_QUEUE_SIZE: u16 = if cfg!(feature = "pci") { 2048 } else { 1024 };
209

2110
/// Default keep alive interval in milliseconds

src/drivers/mod.rs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ pub mod mmio;
1010
pub mod net;
1111
#[cfg(feature = "pci")]
1212
pub mod pci;
13-
#[cfg(any(
14-
all(
15-
not(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci"))),
16-
not(feature = "rtl8139"),
17-
feature = "virtio-net",
18-
),
19-
feature = "fuse",
20-
feature = "vsock",
21-
feature = "console",
22-
))]
13+
#[cfg(feature = "virtio")]
2314
pub mod virtio;
2415
#[cfg(feature = "vsock")]
2516
pub mod vsock;
@@ -38,51 +29,27 @@ pub(crate) type InterruptHandlerQueue = VecDeque<fn()>;
3829
/// passed on to higher layers.
3930
pub mod error {
4031
#[cfg(any(
32+
feature = "virtio",
4133
all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")),
4234
feature = "rtl8139",
43-
feature = "virtio-net",
44-
feature = "fuse",
45-
feature = "vsock",
46-
feature = "console",
4735
))]
4836
use thiserror::Error;
4937

5038
#[cfg(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")))]
5139
use crate::drivers::net::gem::GEMError;
5240
#[cfg(feature = "rtl8139")]
5341
use crate::drivers::net::rtl8139::RTL8139Error;
54-
#[cfg(any(
55-
all(
56-
not(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci"))),
57-
not(feature = "rtl8139"),
58-
feature = "virtio-net",
59-
),
60-
feature = "fuse",
61-
feature = "vsock",
62-
feature = "console",
63-
))]
42+
#[cfg(feature = "virtio")]
6443
use crate::drivers::virtio::error::VirtioError;
6544

6645
#[cfg(any(
46+
feature = "virtio",
6747
all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci")),
6848
feature = "rtl8139",
69-
feature = "virtio-net",
70-
feature = "fuse",
71-
feature = "vsock",
72-
feature = "console",
7349
))]
7450
#[derive(Error, Debug)]
7551
pub enum DriverError {
76-
#[cfg(any(
77-
all(
78-
not(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci"))),
79-
not(feature = "rtl8139"),
80-
feature = "virtio-net",
81-
),
82-
feature = "fuse",
83-
feature = "vsock",
84-
feature = "console",
85-
))]
52+
#[cfg(feature = "virtio")]
8653
#[error("Virtio driver failed: {0:?}")]
8754
InitVirtioDevFail(#[from] VirtioError),
8855

src/drivers/pci.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,9 @@ use crate::drivers::fs::virtio_fs::VirtioFsDriver;
2727
use crate::drivers::net::rtl8139::{self, RTL8139Driver};
2828
#[cfg(all(not(feature = "rtl8139"), feature = "virtio-net"))]
2929
use crate::drivers::net::virtio::VirtioNetDriver;
30-
#[cfg(any(
31-
all(feature = "virtio-net", not(feature = "rtl8139")),
32-
feature = "fuse",
33-
feature = "vsock",
34-
feature = "console",
35-
))]
30+
#[cfg(feature = "virtio")]
3631
use crate::drivers::virtio::transport::pci as pci_virtio;
37-
#[cfg(any(
38-
all(feature = "virtio-net", not(feature = "rtl8139")),
39-
feature = "fuse",
40-
feature = "vsock",
41-
feature = "console",
42-
))]
32+
#[cfg(feature = "virtio")]
4333
use crate::drivers::virtio::transport::pci::VirtioDriver;
4434
#[cfg(feature = "vsock")]
4535
use crate::drivers::vsock::VirtioVsockDriver;
@@ -502,12 +492,7 @@ pub(crate) fn init() {
502492
adapter.device_id()
503493
);
504494

505-
#[cfg(any(
506-
all(feature = "virtio-net", not(feature = "rtl8139")),
507-
feature = "fuse",
508-
feature = "vsock",
509-
feature = "console",
510-
))]
495+
#[cfg(feature = "virtio")]
511496
match pci_virtio::init_device(adapter) {
512497
#[cfg(all(not(feature = "rtl8139"), feature = "virtio-net"))]
513498
Ok(VirtioDriver::Network(drv)) => *crate::executor::device::NETWORK_DEVICE.lock() = Some(drv),

0 commit comments

Comments
 (0)